in reply to Challenge: Number of unique ways to reach target sum
For symmetry reasons, you get the same result as if you calculate the number of ways you can generate 10 * 101 - 667 = 343 as the sum of 10 numbers in 1 .. 100.
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
|
|---|