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
In reply to Golf: Pandigital puzzle by itub
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |