-2

I have a problem. I explain: I have a number for example 273745328191 and the second number for example 3. We know that len(273745328191) is dividable by 3. I want to create two list in the following way:

A=[2+7+3,3+2+8]
B=[7+4+5,1+9+1]

For 273745328191 and 2

A=[2+7,4+5,8+1]
B=[3+7,3+2,9+1]

We assume that the input data is such that the length of both lists A and B will be the same

How to write function which will do that? I dont know it is possible beacuse I'm beginner.

piteer
  • 173
  • 7
  • What about 123456789 and 3? – Scott Hunter Nov 26 '19 at 14:43
  • 123456789 and 3 ,we assume that the input data is such that the length of both lists A and B will be the same – piteer Nov 26 '19 at 14:52
  • For 3 len(number)= 6 or 12 or 18.... – piteer Nov 26 '19 at 14:57
  • For 5 For 3 len(number)= 10 or 20 or 30... – piteer Nov 26 '19 at 14:59
  • bro the question is too difficult. Can you show what you have attempted so we know what you are looking for? – DUDANF Nov 26 '19 at 15:00
  • I want to check who win if two people roll n dices alternately .I was thinking if I add their scores to lists, I will find who win. – piteer Nov 26 '19 at 15:09
  • For exapmle I have result: 12332115 for 2 dices. And A=[1+2=3, 2+1=3],B=[3+3=6, 1+5=6] And win B because 3<6 and 3<6. – piteer Nov 26 '19 at 15:09
  • that's perfectly understandable, why don't you edit your question to include the orignal problem. Q. If two people roll a dice, 10 times, what is the best way to find out who will win? I would personally use a rand to randomize the number. And then jus increment each time you roll the dice. Then compare the two variables and return the larger one. If you edit your question, I'll answer! – DUDANF Nov 26 '19 at 15:13
  • for result 1231 and 1-dice we have A=[1, 3] and B=[2, 1] and 1<2 but 3>1 this time is a draw – piteer Nov 26 '19 at 15:14
  • 2
    If you're rolling six-sided dice, why on earth does your program use numbers as large as 273745328191? It takes extra work to convert a sequence of dice rolls into a single number like that, and it's not a useful form to convert them to. – kaya3 Nov 26 '19 at 15:22
  • Id know how to edit, so I've edited here I want to check who win if two people roll n dices alternately .I was thinking if I add their scores to lists, I will find who win. I have e rasulat for example 213345325166 for two dices. Here won the second person 2+1=3 3+3=6 II 4+5=9 3+2=5 I 5+1=6 6+6=12 II so the second person won. – piteer Nov 26 '19 at 15:24

1 Answers1

1

Ok Here is a function that will show you what you want, I don't know if you need to show the + signes but i hope my code helps you to understand how this works

def split_my_list(mysequence, divider):
    mysequence = str(mysequence)
    split_list = ([mysequence[index-divider: index] for index, value in enumerate(mysequence, 1) if index%divider==0])

    A = [value for index, value in enumerate(split_list) if index%2 ==0]
    B = [value for index, value in enumerate(split_list) if index%2 !=0] 
    print('separated A', A)
    print('separated B', B)

    A = [list(map(int, i)) for i in A]
    B = [list(map(int, i)) for i in B]
    print('mapped A with integers', A)
    print('mapped B with integers', B)

    A = [sum(i) for i in A]
    B = [sum(i) for i in B]

    print("summed values in A", A)
    print("summed values in B", B)


split_my_list(273745328191, 2)
print('='*8)
split_my_list(273745328191, 3)

Output

separated A ['27', '45', '81']
separated B ['37', '32', '91']
mapped A with integers [[2, 7], [4, 5], [8, 1]]
mapped B with integers [[3, 7], [3, 2], [9, 1]]
summed values in A [9, 9, 9]
summed values in B [10, 5, 10]
========
separated A ['273', '191']
separated B ['745', '328']
mapped A with integers [[2, 7, 3], [1, 9, 1]]
mapped B with integers [[7, 4, 5], [3, 2, 8]]
summed values in A [12, 11]
summed values in B [16, 13]

Important references

how to check if number is divisable by another number

python string to integer using map

ThunderHorn
  • 1,975
  • 1
  • 20
  • 42