Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Stamp puzzle solution

by Anonymous Monk
on Jun 08, 2019 at 21:43 UTC ( #11101144=note: print w/replies, xml ) Need Help??


in reply to Stamp puzzle solution

Some nitpicks if you allow. :)

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! =)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11101144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-04-14 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?