top | item 9585907

(no title)

sharth | 10 years ago

So we can actually iterate over every possible solution pretty quickly. If I cared more, I'd look into using `fractions.Fraction` so that I didn't need to use floating point math.

    from __future__ import division
    import itertools
    
    def f(a, b, c, d, e, f, g, h, i):
        return a + 13 * b / c + d + 12 * e - f - 11 + g * h / i - 10
    
    for choices in itertools.permutations(range(1, 10), 9):
        if abs(f(*choices) - 66) < 0.001:
            print choices
There are also some solution that your code will give that are wrong due to your code using integer division.

discuss

order

No comments yet.