## Multiplicative Persistance

### March 26, 2019

Our `per`

function is a little bit different than Matt’s; it returns the sequence in reverse order:

(define (per n) (let loop ((n n) (xs (list))) (if (< n 10) (cons n xs) (loop (apply * (digits n)) (cons n xs)))))

Here’s a quick check:

> (per 327) (8 42 327)

Now we can play. The most common ending number, appearing about 90% of the time, is 0:

> (sort (lambda (x y) (< (cdr y) (cdr x))) (uniq-c = (sort < (map car (map per (range 1 1000001)))))) ((0 . 902609) (6 . 43538) (8 . 32658) (2 . 16673) (4 . 2345) (5 . 2073) (9 . 56) (3 . 21) (7 . 21) (1 . 6))

The most common number of steps is 1, though 2 is not far behind:

> (sort (lambda (x y) ( < (cdr y) (cdr x))) (uniq-c = (sort < (map (lambda (xs) (- (length xs) 1)) (map per (range 1 1000001)))))) ((1 . 402540) (2 . 375227) (3 . 123860) (4 . 66772) (5 . 24654) (6 . 4488) (7 . 2450) (0 . 9))

And here are the records that occur each time a sequence is longer than any previous sequence:

> (let loop ((n 1) (record -1)) (let* ((p (per n)) (len (- (length p) 1))) (when (< record len) (display len) (display " ") (display p) (newline)) (loop (+ n 1) (max record len)))) 0 (1) 1 (0 10) 2 (0 10 25) 3 (4 14 27 39) 4 (8 18 36 49 77) 5 (6 32 48 168 378 679) 6 (0 20 54 336 768 2688 6788) 7 (0 20 54 336 768 2688 27648 68889) 8 (0 20 54 336 768 2688 27648 338688 2677889) 9 (0 20 54 336 768 2688 27648 338688 4478976 26888999) 10 (0 20 54 336 768 2688 27648 338688 4478976 438939648 3778888999) 11 (0 20 54 336 768 2688 27648 338688 4478976 438939648 4996238671872 277777788888899)

I cheated. I let my computer run for a few hours to compute the records up to 10, then stopped the computation and use the known record for 11. You can run the program at https://ideone.com/Vho12W.

In Python. As suggested in the video only certain patterns of numbers is searched. The results come in a few seconds. After that no more numbers are found up to 50 digits.

Strange. My comment ended up in page 2.??

I also went for a Python solution, this one just enumerates multisets of 2..9 (in appropriate order) and uses the number with those digits in ascending order. A few seconds to get up to 277777788888899 (after looking at 435968 multisets), then nothing. https://oeis.org/A003001 has more details.

I noticed an interesting pattern when I calculated the frequency of the final step in the range 1…10^n

1 occurs n times

3 and 7 occur n(n+1)/2 times

9 occurs n(n+1)(n+2)/6 times

I noticed an interesting pattern when I calculated the frequency of the final step in the range 1…10^n

1 occurs n times

3 and 7 occur n(n+1)/2 times

9 occurs n(n+1)(n+2)/6 times

@Ernie: nice observation, looks like the only numbers going to 1 are 100.., going to 3 are 311.. & permutations, going to 7 are 711.. & permutations and going to 9 are 3311… and 911…, with permutations which gives the result you see. For other numbers to end up here, we would need eg. 311111 to have only 2,3,5 and 7 as prime factors which is (presumably) unlikely, though I don’t see why it should be ruled out.

Investigating further, there seems to only a finite number of fundamentally different numbers that end up at something other than 0. The product of digits can only have 2,3,5 and 7 as prime factors so generating multisets of 0..3 gives us all numbers of that form. We quickly get up to 2

39 * 33 * 7**2, but after that everything seems to end up at 0:Here’s a solution in C.

Example Usage: