in reply to Stamp puzzle solution
You know, you could considerably speed up your algorithm by not looping over all results so far in foreach my $c (keys %{$w}) but only those new from the last run. There is no point checking the smaller sums again and again.
And resorting to bash and grep to find the smallest result could be easily avoided by exiting Perl as soon as a sum is missing in %$w
Furthermore, and this is more stylistic, using a hash-slice might be easier to read.
my @w = qw(1 2 3 ...); my $w; @$w{@w} = @w; $w->{0} = 1; # start
Hope this helps! =)
|
|---|