Let p(n) be the probability that a random n-digit integer has all 10 digits occurring (where for simplicity we do include leading 0s; that is, we consider 0000012345 as being a 10-digit number). So p(9) is 0 and p(10) = 10!/1010.
What is the smallest n for which p(n) > 1/2?
Suggested by Danny Lichtblau, Wolfram Research, Inc.
I was trying to solve it analytically, but then I got tired and decided to "cheat". I figured that a very simple Perl script could give me an approximate value for p(n), by generating $N random $n-digit numbers and testing how many of them have every digit. The following code does that while remaining reasonably readable:
#!/usr/bin/perl -l ($n,$N) = @ARGV; for (1 .. $N) { @a = map { int(rand(10)) } 1 .. $n; my %h; @h{@a} = (); $g++ if keys %h == 10; } print $g/$N;
The question now is how short you can make a program that does the same. The only requirements are: 1) take two command-line arguments, $n and $N; and 2) print out the probability followed by a newline (the probability must be computed by the random method).
Generic rules for Perl Golf may be found at http://www.xs4all.nl/~thospel/golf/rules.html
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Golf: Pandigital puzzle
by revdiablo (Prior) on Nov 18, 2004 at 22:41 UTC | |
by tilly (Archbishop) on Nov 18, 2004 at 23:20 UTC | |
by itub (Priest) on Nov 18, 2004 at 23:36 UTC | |
by itub (Priest) on Nov 19, 2004 at 01:28 UTC | |
|
Re: Golf: Pandigital puzzle
by Jenda (Abbot) on Nov 19, 2004 at 01:45 UTC | |
by tilly (Archbishop) on Nov 19, 2004 at 02:37 UTC | |
by dragonchild (Archbishop) on Nov 19, 2004 at 14:18 UTC |