By the way, you can improve your analyze function quite a bit. This piece in particular stood out to me:
Even if you had to use a for loop, you could have just written it as for ( '0000' .. '9999' ) instead. Isn't Perl great? You don't even need the for though. I wrote my analyze function like this:for ( 0 .. 9999 ) { my $k = 0 x ( 4 - length $_ ) . $_;
sub analyze { my $number = shift; my $length = length $number; my $duplicates = 0; my %seen; while (length $number >= 4) { $seen{substr($number, -4)}++ and $duplicates++; substr($number, -1, 1, ''); } my $missing = 10000 - keys %seen; return ($length, $missing, $duplicates) }
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Shortest string containing all from 0000 to 9999 challenge.
by sauoq
in thread Shortest string containing all from 0000 to 9999 challenge.
by EvdB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |