 #### Python cycle to math formula

##### Max. 2000 characters ##### Replies ###### Liza Sain

User

( 7 months ago )

There is some code snippet written on python:

number = 5602004

accum = 0

while number:

accum += (3 * (number % 10))

number = int(number / 10)

accum += (number % 10)

number = int(number / 10)

So, cycle is working while variable number greater then 0. The question is: can this cycle be presented as math formula? User

( 7 months ago )

The formulation is naturally a recurrence relation:

f(n)=f(⌊⌊n10⌋/10⌋)+3(n mod 10)+(⌊n10⌋ mod 10)

This, itself, is most naturally viewed mod 100:

f(n)=f(n without its two rightmost digits)+3×rightmost digit+next-rightmost digit

If n has evenly-many digits, then: take n as a base 10 string. Take the first, third, fifth… digits' sum. Take the second, fourth, sixth… digits' sum, and multiply by 3. Add the two together.

If n has odd-many digits, then just stick a 0 on the front and pretend it has evenly-many.

##### Similar Discussions 25-Sep-2019
##### How do I solve authentication issues with SourceTree?

1 Replies 27-Aug-2019
##### Java error #fgty on git

2 Replies 06-Sep-2019

1 Replies