in reply to Re: Golf: Pandigital puzzle
in thread Golf: Pandigital puzzle

By the rules, my count is 76:
#!/usr/bin/perl -l $N=pop;print 1/$N*grep{%h=map{int rand(10),1}1..$ARGV[0];10==keys%h}1..$N
Incidentally this program, as amusing as it may be, won't give you the exact answer to the puzzle. The following brief program will. (Don't look if you want to figure out the real puzzle for yourself!)
#! /usr/bin/perl use strict; # $stats[$i][$j] will be the number of ways to have used $j different # digits in a $i digit number. my @stats = [1, map 0, 1..10]; my $i = 0; while ($stats[$i][10]*2 < 10**$i) { my $last_stats = $stats[$i]; $i++; my $next_stats = $stats[$i] = [map 0, 0..10]; for my $j (0..10) { $next_stats->[$j] += $j*$last_stats->[$j]; $next_stats->[$j+1] += (10 - $j)*$last_stats->[$j]; } } print $i, "\n";

Replies are listed 'Best First'.
Re^3: Golf: Pandigital puzzle
by itub (Priest) on Nov 18, 2004 at 23:36 UTC
    You can still squeeze three more characters:
    (I played with the option of wasting half the random numbers, but it seems it's not really useful...)

    #!/usr/bin/perl -l $N=pop;print 1/$N*grep{%h=map{int rand 10}1..$ARGV[0]*2;9<keys%h}1..$N
Re^3: Golf: Pandigital puzzle
by itub (Priest) on Nov 19, 2004 at 01:28 UTC
    Look, no hashes! But 77 chars long...
    #!/usr/bin/perl -l $N=pop;print 1/$N*grep{my@a;$a[rand 10]++for 1..$ARGV[0];9<grep$_,@a}1 +..$N