Assume you want to buy four items in a supermarket. If you add the prices together, you get CHF 7.77. If you multiply the prices, you also get CHF 7.77. How much did the items cost?
Well, by trying out all possible combinations that add up to CHF 7.77
You can guess two numbers and calculate the other two. Repeat until you have the right numbers.
(a few tries later)
It might be a bit hard to solve this by hand, because the smallest possible price is CHF 0.01
Yes, the program I wrote. It automatically searches for all possible combinations, it prints out the first one it finds. The program converts all decimals to integers, because we want to work with accurate numbers wherever possible.
What number do you want to get? (7.77 by default)
7.77
How many items are there? (4 by default)
4
Closest match: 7.77
Possible Combinations:
0.8, 1.25, 2.22, 3.5
0.8, 1.25, 3.5, 2.22
0.8, 2.22, 1.25, 3.5
0.8, 2.22, 3.5, 1.25
0.8, 3.5, 1.25, 2.22
0.8, 3.5, 2.22, 1.25
1.25, 0.8, 2.22, 3.5
1.25, 0.8, 3.5, 2.22
1.25, 2.22, 0.8, 3.5
1.25, 2.22, 3.5, 0.8
1.25, 3.5, 0.8, 2.22
1.25, 3.5, 2.22, 0.8
2.22, 0.8, 1.25, 3.5
2.22, 0.8, 3.5, 1.25
2.22, 1.25, 0.8, 3.5
2.22, 1.25, 3.5, 0.8
2.22, 3.5, 0.8, 1.25
2.22, 3.5, 1.25, 0.8
3.5, 0.8, 1.25, 2.22
3.5, 0.8, 2.22, 1.25
3.5, 1.25, 0.8, 2.22
3.5, 1.25, 2.22, 0.8
3.5, 2.22, 0.8, 1.25
3.5, 2.22, 1.25, 0.8