Enigmatic Code

Programming Enigma Puzzles

Enigma 1582: Bit tricky

From New Scientist #2747, 13th February 2010 [link]

Joe thought he would test Penny’s ability to manipulate equations this week. So he asked her to find the values of the integers A, B and C in the following equation.

(A.B + 1) ÷ (A.B.C + A + C) = 0.138

What are the values of A, B and C?

Note: If it’s not obvious this is a division: ((A×B) + 1) / ((A×B×C) + A + C) = 0.138



2 responses to “Enigma 1582: Bit tricky

  1. jimrandell 1 February 2012 at 10:00 am

    It’s easy to find a solution to this problem without programming.

    The equation can be rewritten as:

    (AB + 1) / ((AB + 1)C + A) = 69/500

    Clearly (AB + 1) cannot be zero (as it is the numerator for a non-zero fraction), so we can rewrite the equation as:

    C + A/(AB+1) = 7 + 17/69

    At this point we can equate the integer and fractional parts and it is easy to see a solution:

    C=7, A=17, B = (69 – 1) / 17 = 4.

    But is it the only solution?

    If we consider the case where A and B are both positive integers, then it is clear than 0 < (A / (AB + 1)) < 1, so C can only be 7, leaving:

    (A / (AB + 1)) = 17 / 69

    So suppose: A = 17n and AB + 1 = 69n for some positive integer n. Substituting for A we get, 17nB + 1 = 69n, which rewriting for n gives:

    n = 1 / (69 – 17B)

    Which can only have an integer solution of n=1, when 69 – 17B = 1, i.e. B = 68/17 = 4.

    So it is indeed the only solution where A, B are positive integers.

    Also A cannot be zero. If it is the original equation reduces to: 1/C = 69/500, and if B is zero the equation reduces to 1/(A+C) = 69/500, both of which are impossible to satisfy.

    You can then consider the cases where, (A, B < 0), (A > 0), (B > 0) by rewriting the equation in terms of positive -a and -b, as necessary and following reasoning similar to that above to show that no further integer solutions are possible.

    Solution: A=17, B=4, C=7.

  2. Jim Randell 2 January 2014 at 10:43 am

    Here’s a programmatic solution. It tests integer triples (A, B, C) until it finds a solution. It runs in 88ms.

    from itertools import product, count
    from enigma import printf
    def check(A, B, C):
      n = A * B + 1
      d = A * B * C + A + C
      if 500 * n == 69 * d:
        printf("A={A} B={B} C={C}")
        return True
      return False
    def test(A, B, C):
      return any(check(*s) for s in product((A, -A), (B, -B), (C, -C)))
    def solve():
      for s in count(0):
        for A in range(0, s):
          for B in range(0, s):
            C = s - (A + B)
            if test(A, B, C):

    This means I can remove the puzzle from my list of Enigmas that I have not solved programatically.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: