Searching for a sum

1

In this challenge you will take two inputs One input will be a string of numbers of any length which you will put into an array/table/whatever you call it in your language Ex:

10 10 145 20 53 102 20

Would become

arraynameofyourchoice = {10, 10, 145, 20, 53, 102, 20}

You can assume the input will have spaces in between each number and no newlines.

The second input will be our sum, which will be a number Ex:

165

Your challenge is to make a script that will search through your array and find every possible way to get 165 by adding numbers in the array. You can output your code in any way that clearly shows what numbers you are adding.

So in our example the output would be:

10, 10, 145
145, 20
53, 102, 10

Because each of those sequences of numbers added together equal 165

Note that even though there are 2 twenties in the sequence we did not output

145, 20

twice. You can never have a repeated sequence. Your code will take a +5 byte penalty if it does something like this:

145, 20
20, 145

This is fastest code challenge so fastest code wins! good luck!

user40734

Posted 2015-05-16T12:27:41.920

Reputation:

Question was closed 2015-05-16T12:33:25.860

If I changed this to a fastest code challenge would it still be a duplicate? – None – 2015-05-16T12:50:03.040

It's probably different then, but this needs some work to be a proper fastest code challenge. For a start the 5-byte penalty no longer makes sense. Furthermore, you'll have to run all submissions on your own machine, so that timings can be compared fairly. And lastly, you would have to include some large test sets that actually allow you to measure timings meaningfully. – Martin Ender – 2015-05-16T14:53:02.890

No answers