For those who are not familiar with the game. You are given 8 numbers, and you need to achieve the goal using +, -, / and *.
So, if the goal is 254, and your game numbers are 2, 50, 5, 2, 1, you will correctly answer the question by indicating 5 * 50 = 250. Then 2 + 2 - four. Add this to get 254.
Some game videos are here:
Video 1 Video 2
Basically, I roughly force the game to use, generating all perms of all sizes for numbers and all character Persians and use a basic calculator to calculate the solution.
However, it contains a drawback, because all decisions are solved as follows: (((((1 + 1) * 2) * 3) * 4). He does not rearrange the brackets and causes me a headache.
Therefore, I can not solve every equation. For example, given
Target 16 and numbers 1,1,1,1,1,1,1,1,1 it fails if it should do (1 + 1 + 1 + 1) * (1 + 1 + 1 + 1) = 16.
I would love it if someone could finish it ... in any language.
This is what I wrote so far:
Here is an example output:
[15:53: /mnt/mydocuments/git_working_dir/countdown_solver$] perl countdown_solver.pl Symbol table: +, -, /, *, +, -, /, *, +, -, /, *, +, -, /, *, +, -, /, *, +, -, /, *, +, -, /, *, +, -, /, *Total number of permutations: 93928268313 Perms of size: 2. BEST SOLUTION SO FAR: (2 + 4) = 6 (distance from target 751 is 745) BEST SOLUTION SO FAR: (2 * 4) = 8 (distance from target 751 is 743) BEST SOLUTION SO FAR: (4 + 7) = 11 (distance from target 751 is 740) BEST SOLUTION SO FAR: (4 * 7) = 28 (distance from target 751 is 723) BEST SOLUTION SO FAR: (4 * 9) = 36 (distance from target 751 is 715) BEST SOLUTION SO FAR: (7 * 9) = 63 (distance from target 751 is 688) BEST SOLUTION SO FAR: (4 * 50) = 200 (distance from target 751 is 551) BEST SOLUTION SO FAR: (7 * 50) = 350 (distance from target 751 is 401) BEST SOLUTION SO FAR: (9 * 50) = 450 (distance from target 751 is 301) Perms of size: 3. BEST SOLUTION SO FAR: ((4 + 7) * 50) = 550 (distance from target 751 is 201) BEST SOLUTION SO FAR: ((2 * 7) * 50) = 700 (distance from target 751 is 51) BEST SOLUTION SO FAR: ((7 + 9) * 50) = 800 (distance from target 751 is 49) BEST SOLUTION SO FAR: ((9 + 6) * 50) = 750 (distance from target 751 is 1) Perms of size: 4. BEST SOLUTION SO FAR: (((9 + 6) * 50) + 1) = 751