in reply to Golf: Pandigital puzzle

Just to get it started, he's a minor improvement:

#!/usr/bin/perl -l ($n,$N) = @ARGV; for (1 .. $N) { my %h; $h{int rand 10}++ for 1 .. $n; $g++ if keys %h > 9; } print $g/$N;

Update: here's another minor improvement on that:

#!/usr/bin/perl -l ($n,$N) = @ARGV; for (1 .. $N) { %h = map { int rand 10, "" } 1 .. $n; $g++ if keys %h > 9; } print $g/$N;

Cheap update: removing the whitespace:

#!/usr/bin/perl -l ($n,$N)=@ARGV; for(1..$N){ %h=map{int rand 10,""}1..$n; keys%h>9&&$g++ } print$g/$N;

Yet another (and hopefully final) update: here are the counts, as reported by the golfcount program:

145: itub 121: revd1 117: revd2 87: revd3

Replies are listed 'Best First'.
Re^2: Golf: Pandigital puzzle
by tilly (Archbishop) on Nov 18, 2004 at 23:20 UTC
    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";
      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
      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