+ 9

List problem -> mapping

Given a sequence of 0 and 1. do the following from right to left: 1st number * 1 2nd number * 2 3rd number * 4 4th number * 3 5th number * 1 6th number * 2 7th number * 4 8th number * 3 ... at last step sum it. eg: 100111011 100213021 1+2+1+3+2+1 = 10

19th Apr 2018, 6:47 PM
Oma Falk
Oma Falk - avatar
2 Answers
+ 2
Do this num=reversed([int(i) for i in str(x)]) mult=[1,2,4,3] f_sum=0 for i,j in enumerate(num): f_sum+=mult[i%4]*j
19th Apr 2018, 7:40 PM
Koushik Naskar
Koushik Naskar - avatar
+ 4
@Jan Markus Koushik Naskar nice! If sum is devisible by 5, the binary is it too. the sequence for 7 is 1 2 4 1 2 4... for 9: 1 2 4 8 7 5 1 2 4 5... if sum is devisible by 7 / 9 the binary is it too.
19th Apr 2018, 8:44 PM
Oma Falk
Oma Falk - avatar