in reply to Coming soon: Algorithm::Loops
Anyway, my program is after the readmore tag.
Abigail
#!/usr/bin/perl use strict; use warnings; my $from = 2000; my $till = 3000; my @nums; for my $x (0 .. 9) { for my $y ($x .. 9) { for my $z ($y .. 9) { my %seen; push @nums => [grep {!$seen {$_} ++} map {s/^0{1,2}//; $_} "$x$y$z", "$x$z$y", +"$y$x$z", "$y$z$x", "$z$x$y", +"$z$y$x"] } } } sub all_sub_sets; sub all_sub_sets { return unless @_; my $f = shift; my @r = all_sub_sets @_; @r => [$f] => map {[$f => @$_]} @r } my %answers; foreach my $num (@nums) { my @sets = all_sub_sets @$num; foreach my $set (@sets) { local $" = " + "; my $sum = eval "@$set"; if ($sum >= $from && $sum < $till) { push @{$answers {$sum}} => $set; } } } for my $sum ($from .. $till - 1) { local $" = " + "; print "$sum = @{$answers{$sum}[0]}\n" if $answers {$sum} && 1 == @{$answers {$sum}}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Coming soon: Algorithm::Loops (puzzle2)
by tye (Sage) on Apr 12, 2003 at 07:06 UTC | |
by Abigail-II (Bishop) on Apr 12, 2003 at 23:25 UTC |