#!/usr/bin/perl use strict; use Data::Dumper; $|++; my %PossibleTotals = (); %{$PossibleTotals{1}} = (9, "9"); %{$PossibleTotals{2}} = (9+9, "(9+9)", 9-9, "(9-9)", 9*9, "(9*9)", 9/9 +, "(9/9)"); foreach my $WhichNine (3..9) { print "Working $WhichNine\n"; for (my $Count = 1; $Count <= $WhichNine / 2; $Count++) { # print "Doing $Count, $WhichNine - $Count\n"; foreach my $Column1 (keys %{$PossibleTotals{$Count}}) { foreach my $Column2 (keys %{$PossibleTotals{$WhichNine - +$Count}}) { ${$PossibleTotals{$WhichNine}}{$Column1 + $Column2} = + "(" . ${$PossibleTotals{$Count}}{$Column1} . "+" . +${$PossibleTotals{$WhichNine - $Count}}{$Column2} . ")"; ${$PossibleTotals{$WhichNine}}{abs($Column1 - $Column +2)} = "(" . ${$PossibleTotals{$Count}}{$Column1} . "-" . +${$PossibleTotals{$WhichNine-$Count}}{$Column2} . ")"; ${$PossibleTotals{$WhichNine}}{$Column1 * $Column2} = + "(" . ${$PossibleTotals{$Count}}{$Column1} . "*" . +${$PossibleTotals{$WhichNine-$Count}}{$Column2} . ")"; ${$PossibleTotals{$WhichNine}}{sprintf("%.15f", $Colu +mn1 / $Column2)} = "(" . ${$PossibleTotals{$Count}}{$Column1} . "/" . +${$PossibleTotals{$WhichNine-$Count}}{$Column2} . ")" if ($Column2 != + 0); ${$PossibleTotals{$WhichNine}}{sprintf("%.15f", $Colu +mn2 / $Column1)} = "(" . ${$PossibleTotals{$WhichNine-$Count}}{$Column +2} . "/" . ${$PossibleTotals{$Count}}{$Column1} . ")" if ($Column1 != + 0); } } } } print "finished calculating\n"; my (@FoundNumbers) = (); my %TempHash = (); foreach (keys %{$PossibleTotals{9}}) { {$TempHash{int($_)} = 1 if (($_ < 10000) && (int($_) == sprintf("% +.7f", $_))); print "$_ : ${$PossibleTotals{9}}{$_}\n" if $_ =~ /^19[45]\./; } (@FoundNumbers) = sort {$a<=>$b} keys (%TempHash); my $Count = 0; while (@FoundNumbers) { my $Number = shift(@FoundNumbers); if (($Count == $Number) && (${$PossibleTotals{9}}{$Number} =~ /[9\ +D]{9}/g)) { print "$Number = " .${$PossibleTotals{9}}{$Number} . "\n"; } else { print "The first number missed is $Number\n"; last; } $Count++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: As per Tilly, The 9 nines solution
by tilly (Archbishop) on Feb 07, 2002 at 07:06 UTC | |
|
Re: As per Tilly, The 9 nines solution
by BeernuT (Pilgrim) on Feb 06, 2002 at 23:57 UTC |