While I have mastered almost all easy-puzzles without trouble, I am completely stuck at this one:
They given example just doesn’t tell me how this cost thing works, if there are multiple numbers. Well at first I thought I would understand:
numbers: 1,2,3
1+2= 3
3+3= 6
Total cost: 9 (correct)
The only way I get to 261 is, when I do the following:
9+9= 18
18+9+9= 36
36+9+9= 54
54+9+9= 72
72+9= 81
Total cost: 261
But this algorithm doesn’t work with the first two examples. I cannot find an algorithm that works for all of the 3 examples.
Can anyone help me to understand this puzzle? I have already spent at least 5 hours trying to understand what is wanted… I would really appreciate if someone could bring some sense into this
You must find the lowest cost, which you can’t get by simply adding numbers in sequence.
For example :
9+9+9+9 :
sum first 9s : 9+9 = 18 -> your numbers are 18,9,9
9+9 = 18
18+18 = 36
You can only add two numbers. Not a+b+c, only a+b, then (a+b)+c.
so you can also try b+c, then (b+c)+a
each time you add two numbers, the result of that addition is “the cost”
ignore the costs for a moment.
you need to add up all numbers to get the total sum.
since you can only ever add up two numbers at the same time, you have to use the intermediate sums as new numbers…
a short array:
1 2 3 4 5
add up 1 and 2, sum: 3. now 1 and 2 are used, and 3 is your new summand.
new array after step one:
3 3 4 5
add up 3 and 3, sum: 6. now 3 and 3 are used, and 6 is your new summand.
new array after step two:
6 4 5
add up 6 and 4, sum: 10. now 6 and 4 are used, and 10 is your new summand.
new array after step three:
10 5
last step: 10+5
each step uses one addition. which has a cost you need to add up.
headscratch does that make it clearer? i’m not the best at explaining stuff
I can’t have 100% to the test. I followed the algothme describe above. Every “round” sum the two minimum card. Any idea why it doesn’t pass all the tests?