Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Challenge: Number of unique ways to reach target sum

by ambrus (Abbot)
on Feb 15, 2006 at 14:18 UTC ( [id://530383]=note: print w/replies, xml ) Need Help??


in reply to Challenge: Number of unique ways to reach target sum

This can speed the calculation to twice three times faster with a minimal change in the program, and eight four times faster if you

Here's the resulting faster variant of my script: (Update: I've removed the redundant code from this snippet, as noted on Re: Challenge: Number of unique ways to reach target sum and updated the benchmarks accordingly)

This of course works only in those solutions which calculate the number of possibilities only, not for those that iterate on them all.

Update: blokhead's reply has another interesting optimization.

Update:

like blokhead does makes it even more faster (with 40%). Here's the newer code.

Update: Improving this a tad bit more, we get

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-26 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found