I also watched the video this morning, not realizing it came up because it was new.

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:

#!/usr/bin/perl use strict; use warnings; use feature qw( say ); use Function::Parameters; $| = 1; # Try the record-holder try_num(277777788888899, 1); # Search for record holders at each # iterations my $num = my $max = my $maxn = my $print = 0; while (1) { ++$num; my ($per, $new) = (persist($num), 0); (0 == $num % 100_000) and $print = 1; ($per > $max) and ($maxn, $max, $print, $new) = ($num, $per, 1, 1) +; $print and print " CURR=$num, MAX=$max, MAXP=$maxn\e[K\r"; $new and say ""; $print = $new; } fun try_num($num, $dbg = 0) { my $per = persist($num, $dbg); printf "\e[102m Count[$num] = %s\e[m\n\n", persist($num, $dbg); } fun muldigs($num, $dbg = 0, $res = 1) { $dbg and say " Num: $num"; my @dbg = ( ); map { push @dbg, ($res *= $_) } split(//, $num); $dbg and say " -> " . join(",", @dbg); return $res; } fun persist($num, $dbg = 0) { my ($mul, $iter) = ($num, 0); while (1) { (length($mul) > 1) or return $iter; ($iter, $mul) = ($iter+1, muldigs($mul, $dbg)); $dbg and say "Iter: $iter [$mul]\n"; } }
say  substr+lc crypt(qw $i3 SI$),4,5

In reply to Re: Multiplication digit persistence by golux
in thread Multiplication digit persistence by tobyink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.