## Algorithm for placing plus and minus signs between digits so that the result is 100

December 7, 2013 2 Comments

Yesterday I found the following programming problem:

*Write a program that outputs all possibilities to put + or – or nothing between the numbers 1,2,…,9 (in this order) such that the result is 100.*

This problem has 11 solutions and they are demonstrated here: Fun with numbers: place plus/minus signs between the digits.

1 + 2 + 34 – 5 + 67 – 8 + 9 = 100

12 + 3 – 4 + 5 + 67 + 8 + 9 = 100

123 – 4 – 5 – 6 – 7 + 8 – 9 = 100

123 + 4 – 5 + 67 – 89 = 100

123 + 45 – 67 + 8 – 9 = 100

123 – 45 – 67 + 89 = 100

12 – 3 – 4 + 5 – 6 + 7 + 89 = 100

12 + 3 + 4 + 5 – 6 – 7 + 89 = 100

1 + 23 – 4 + 5 + 6 + 78 – 9 = 100

1 + 23 – 4 + 56 + 7 + 8 + 9 = 100

1 + 2 + 3 – 4 + 5 + 6 + 78 + 9 = 100

But the page in the link provides only answers without an algorithm, that’s why I decided to write it myself.

Read more of this post