in reply to Shortest string containing all from 0000 to 9999 challenge.
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.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Shortest string containing all from 0000 to 9999 challenge.
by EvdB (Deacon) on May 22, 2003 at 11:48 UTC |