#1
  1. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,968
    Rep Power
    374

    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. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,960
    Rep Power
    9397
    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