Saturday, September 18, 2021

Program to find the maximum multiplicative persistence

After watching an interesting video from Numberphile about multiplicative persistence, one of the basic operations in Persistence of numbers, I thought that I wanted to make it by myself in Perl, so here you have the program multdigits.pl:

$ perl multdigits.pl -h

Usage: perl multdigits.pl [OPTION]...
Multiply the digits of each integer recursively until get one digit,
printing all the products obtained and counting the number of them.
See https://oeis.org/A003001 for more information about the sequence.

-r, --radix=NUM   use the NUM radix or base, 10 by default
-s, --sorted      use only numbers with sorted digits as optimization
-m, --mindigit=N  when sorted, minimum digit to optimize, 1 by default
-a, --all         prints all instead of only those with more products
-o, --others      prints others with same product number, not 1st only
-d, --dots        print dots when reaches a number with one digit more
-i, --initial=NUM initial number to begin the search, 0 by default
-h, --help        print the help and exits

Faster options: perl multdigits.pl --sorted --mindigit=2 --indicator
Copyright 2021 Carlos Rica <jasampler AT gmail DOT com>

Using the faster options it finds pretty fast the smallest integer (277777788888899) having the maximum multiplicative persistence known (11) for base 10, and then the program cannot reach numbers much bigger than that, but it can do it in any base, and also it can show other numbers with the same maximum multiplicative persistence, which give interesting information about the repetition of the longest sequences of products. Enjoy!

No comments:

Post a Comment