still, on paolo’s puzzle
well, i just minimized the number of loops.
the ones place of the first digit must not be one. hint: identity property of multiplication.
the tens place must be something not greater than 4. why? because numbers 5-9 will generate two digit products if multiplied to any number except one. right? the largest possible equation you can make using the range 1 to 9 that will yield a single digit product is 4 multiplied to 2 which is eight. exlcusive from multiplying by one of course.
that limits the first number to 49. still, excluding the numbers 1 ,11 , 21, 31, 41, 22, 33, 44 i have set 41 possible hard limit combinations to the first, two digit number. (or so, i honestly think)
the third number (the multiplier), can’t possibly be one. again because of identity property of multiplication.
then i thought that i need to construct a condition statement that prevents the program from descending deeper into the code in case the product:
a) is a three digit number or mathematically speaking, product/100 = true, (remembering that “not zero” is always “true”, (x) digit numbers will always yield zero when integer divided by (x+1) or more digit divisors.)
b) has zero for it’s tens place e.g. 10, 20, 30 … or simply !(product%10)
d) has digits that are already taken
then, i can remove two more nested loops and some codition statements in the old program because i can already make another set of logic block comparisons using the generated product.
instinctively of course, i only needed to determine if the final answer’s tens place digit and ones place digit are not taken for the program to complete.
whereas the old program did 2745 loops to solve the magic order, the new one solves the same puzle in a relatively smaller number of iterations.
see?
amerei@heaven ~/git/null/public $ ./puzzle 17 * 4 ---- 68 + 25 ---- 93 it took 422 loops.
i therefore conclude that i suck at math.

wooooooooooooooo! very nice! ^-^ well done niel ^-^
Comment by lynlyn — December 12, 2005 @ 7:27 am
thanks.
you should try doing this in other languages too.
e.g. perl, python and java are good candidates. and as what paolo (the guy who inspired me to solve this puzzle) said, you can learn many things from doing this.
Comment by sleepy jenkins — December 12, 2005 @ 6:33 pm