in reply to Vampire Numbers Revisited
Update: better way of excluding short factors.my $digits = 2; my @mods; for ([0,0],[2,2],[3,6],[5,8],[6,3],[8,5]) { $mods[$_->[0]] = $_->[1]; } my $min_factor = 1 . (0 x ($digits-1)); for my $a ($min_factor .. (9 x $digits)) { if (defined $mods[$a % 9]) { for (my $b = $min_factor - 1 + ($mods[$a % 9]||9); $b <= $a; $ +b += 9) { my $prod = $a * $b; my $fdigits = join '', sort map {split //} $a, $b; my $pdigits = join '', sort split //, $prod; if ($pdigits eq $fdigits) { print "$a * $b = $prod\n"; } } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Vampire Numbers Revisited
by tall_man (Parson) on Mar 24, 2005 at 20:17 UTC |