Try to find a number that takes more than eleven steps.
use v5.10; use strict; use warnings; use List::Util qw(product); sub per { my ($n) = @_; return if $n < 10; my $p = product split //, $n; return $p, per($p); } my @steps = per 277777788888899; my $steps = @steps; say "$steps steps"; say for @steps;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Multiplication digit persistence
by haukex (Archbishop) on Mar 21, 2019 at 13:26 UTC | |
Try to find a number that takes more than eleven steps. Heh, I guess you just watched the Numberphile video that was just released? ;-) | [reply] [d/l] |
by tobyink (Canon) on Mar 21, 2019 at 13:31 UTC | |
Indeed. | [reply] |
|
Re: Multiplication digit persistence
by choroba (Cardinal) on Mar 21, 2019 at 17:41 UTC | |
Also, put somewhere to the top, and enclose the to-be-winner in quotes.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |
by tobyink (Canon) on Mar 22, 2019 at 10:20 UTC | |
Tbh, I doubt that's enough. product is written in C. You'd probably want to replace it with a Math::BigInt version. | [reply] [d/l] |
|
Re: Multiplication digit persistence
by golux (Chaplain) on Mar 21, 2019 at 15:03 UTC | |
When I saw that Matt was using Python to code it, of course I wanted to try it in Perl instead! This was what I came up with:
| [reply] [d/l] |
by jwkrahn (Abbot) on Mar 21, 2019 at 19:21 UTC | |
You are not using printf correctly.
The first argument is a FORMAT string and using variable interpolation could introduce an invalid '%' character.
You are not using map correctly:
| [reply] [d/l] [select] |
by ikegami (Patriarch) on Mar 21, 2019 at 19:41 UTC | |
Not many numbers have % as a digit. | [reply] [d/l] |
|
Re: Multiplication digit persistence
by johngg (Canon) on Mar 28, 2019 at 11:47 UTC | |
I don't have the math skills to know whether there is some formula to find the "steps" so a brute force approach was my only option. Initially I used glob with multiples of the {1,2,3,4,5,6,7,8,9} pattern to generate an array of n-digit numbers to test but that was wasteful. All that is needed are numbers where digits are equal or greater than the preceding digit. I used Math::BigInt to cope with large values and initially used ->bmul() to find the product of all the digits. However, changing
to
produced gains in performance as the length of the numbers increased. I tried to make further gains by employing threads but the results were woeful; I am obviously not understanding something about them and where they can usefully be employed and may well raise a SoPW to seek enlightenment. The code:-
Running the script with no arguments tests numbers of length 2 through 8 digits. Read more... (2 kB)
The script successfully finds the 15-digit value with 11 steps but I have yet to find a 12 stepper, having run with up to 27-digit values. Output from a 26- and 27-digit run below:- Read more... (2 kB)
As you can see, the above run finds all the steps up to 11, just with a series of 1s prepended and the whole run took almost 9 hours on a 2012 MacBook Pro 2.3GHz quad core i7. It may be that there are no 12-steppers at all, I don't have the maths to tell, but I think any further tests will have to be using a faster language. Perhaps this will be a good project to translate to Go, as I try to learn more. Update: Corrected typo, s/MacBoon/MacBook/ Cheers, JohnGG | [reply] [d/l] [select] |
by pryrt (Abbot) on Mar 28, 2019 at 13:34 UTC | |
It was mentioned in the video, and I am quoting the similar idea from the Wolfram MathWorld Multiplicative Persistence article: "There is no number <10^(233) with multiplicative persistence >11". You're going to have to go a lot higher than 27 digits if you want to find the elusive 12-stepper. I tried talking the lowest 11-stepper (277777788888899), then permuting its digits, and listing the factors of each of those permutations (keeping the single-digit factors separate, then lumping what's left if it's not), trying to find one or more permutations that is soley made up of single-digit factors -- because if there's a group of only-single-digit factors that make up a 11-stepper, then making a 12-stepper is as simple as concatenating those digits. -- Actually, I remembered that I started with a 10-stepper, because I wanted to see if I could proof-of-concept it to go from the 10-stepper to a known 11-stepper. I only made it about a million permutations through. If I had started with the 11-stepper, that would have been almost enough, because there are only 15! / 6! / 6! / 2! permutations of 277777788888899, which is 1.3million permutations. But since I was using the 10-stepper 4996238671872 => 1223466778899, which has fewer repeating digits, so is 13!/2!/2!/2!/2!/2! = 195million permutations. Looks like I'll have to find some spare CPU cycles to try the 11-stepper, too. <Reveal this spoiler or all in this thread> | [reply] [d/l] |
by LanX (Saint) on Mar 28, 2019 at 14:16 UTC | |
But you know that'll fail? updateProbably I didn't think it thru, the product of more than 50 digits could contain many 1s acting as fillers in between your targeted 15 digits... in other words 1277777788888899 is am eleven stepper too, just not the smallest. BTW: For the same reason is 1223466778899 not the smallest 10 stepper.
Cheers Rolf
| [reply] |
by pryrt (Abbot) on Mar 28, 2019 at 15:45 UTC | |
by LanX (Saint) on Mar 28, 2019 at 16:52 UTC | |
| |