When you divide the successive powers of `10` by `13` you get the following remainders of the integer divisions:  

`1, 10, 9, 12, 3, 4`. 

Then the whole pattern repeats.

Hence the following method:
Multiply the right most digit of the number with the left most number 
in the sequence shown above, the second right most digit to the second 
left most digit of the number in the sequence. The cycle goes on and you sum all these products. Repeat this process until the sequence of sums is stationary.

...........................................................................

Example: What is the remainder when `1234567` is divided by `13`?

`7×1 + 6×10 + 5×9 + 4×12 + 3×3 + 2×4 + 1×1 = 178`

We repeat the process with 178:

`8x1 + 7x10 + 1x9 = 87`

and again with 87:

`7x1 + 8x10 = 87`

...........................................................................

From now on the sequence is stationary and the remainder of `1234567` by `13` is 
the same as the remainder of `87` by `13`: `9`

Call `thirt` the function which processes this sequence of operations on an integer `n (>=0)`. `thirt` will return the stationary number.

`thirt(1234567)` calculates 178, then 87, then 87 and returns `87`.

`thirt(321)` calculates 48, 48 and returns `48`

Difficulty: introductory

Starter code:

def thirt(n):
	

Solutions:
array = [1, 10, 9, 12, 3, 4]

def thirt(n):
    total = sum([int(c) * array[i % 6] for i, c in enumerate(reversed(str(n)))])
    if n == total:
        return total
    return thirt(total)


import itertools as it

def thirt(n):
    if n < 100: return n
    
    pattern = it.cycle([1, 10, 9, 12, 3, 4])
    
    return thirt(sum(d*n for d,n in zip(list(map(int, str(n)[::-1])), pattern)))


def thirt(n):
  seq = [1, 10, 9, 12, 3, 4]
  s = str(n)
  t = sum(seq[i%6] * int(s[-i-1]) for i in range(len(s)))
  return t if t == n else thirt(t)

from itertools import cycle

def thirt(n):
    c = cycle([1, 10, 9, 12, 3, 4])
    m = sum( int(l)*next(c) for l in str(n)[::-1] )
    return m if m == n else thirt(m)

def thirt(n):
    w = [1, 10, 9, 12, 3, 4]
    while True:
        r = n; q = -1; c = 0; j = 0
        while (q != 0):
            q = int(r / 10)
            c += (r % 10) * w[j % 6]
            r = q
            j += 1
        if (c == n): return c
        n = c

seq = (1, 10, 9, 12, 3, 4)

def thirt(n):
    strn = str(n)[::-1]
    m = sum(seq[i % 6] * int(strn[i]) for i in range(len(strn)))
    return n if n == m else thirt(m)

def thirt(n):
    p = [1, 10, 9, 12, 3, 4]
    ns = sum(int(c) * p[i % len(p)] for i, c in enumerate(str(n)[::-1]))
    return ns if ns == n else thirt(ns)

from itertools import cycle
def thirt(n):
    while True:
        pattern = cycle((1, 10, 9, 12, 3, 4))
        total = sum(int(a) * next(pattern) for a in reversed(str(n)))
        if total == n:
            return total
        n = total

def thirt(n):
      sequence = [1,10,9,12,3,4]
      numbers = str(n)[::-1]
      sum = 0
      for i in range(len(numbers)):
          sum += int(sequence[i%6])*int(numbers[i])
      if sum == n:
          return sum
      else:
          return thirt(sum)
        
            


from itertools import cycle

def thirt(n):
    m = -n
    while m != n:
        m = n
        n = sum(x * y for x, y in zip(cycle([1, 10, 9, 12, 3, 4]), map(int, str(n)[::-1])))
    return n