1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Rep Power

    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.
  2. #2
  3. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    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.

IMN logo majestic logo threadwatch logo seochat tools logo