November 3rd, 2012, 05:49 PM
Countdown conundrum - game - need pointers?
Strictly not php, but I will be using php.
game works like this:
You ask for 6 numbers (2 big numbers from: 25, 50, 75, 100) ,and 4 small numbers (1-10) a random target is chosen which you have to reach using the numbers and + - / *.
I am trying to emulate this via php.
Now i tried to code like a human would like:
target/big number. if no remainder.. done. if remainder, try to use other numbers to get that remainder..
lots of if/elsif..
Then i got fed up and i just use a script to pick between 1-6 numbers, random signs and then eval the numbers/signs to see the result. if result = target i stop looping.
It works most of the time but it is pure trial and error.
Is there a better way of approaching?
Please note: i am not looking for solution but rather pointers to how i should approach this.
November 3rd, 2012, 09:01 PM
Brute force is the most obvious one, and it only turns out to be 737,280 possible combinations. If you have to use all of them. 946,680 if not.
It's essentially a bunch of loops. Just be sure you don't reuse a number.