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";