Enigmatic Code

Programming Enigma Puzzles

Enigma 71: Some very cross numbers

From New Scientist #1214, 14th August 1980 [link]

It might be said — indeed it has been said — that Uncle Bungle has a genius for getting things wrong. This has not hitherto ruffled the imperturbability of his temper, but the other day, perhaps as a result of excessive pulling of a leg that has perceptibly lengthened through the years, something snapped. “All right”, he said crossly, “if you say I get things wrong I’ll get things wrong”. And he proceeded to produce a cross-number puzzle in which every single clue was incorrect. And this time there was no mistake in the mistakes. (There are no 0’s in the solution). The puzzle was as follows:

Enigma 71

Across:
1-2-3
  Not a multiple of 3 and of 5 and of 7.
4-5-6  The sum of the digits is greater than 5.
7-8-9  The last digit is less than the sum of the first two.

Down:
1-4-7
 The sum of the digits is less than 19.
2-5-8  The sum of the digits is greater than the sum of digits of 3 down.
3-6  An odd number.

Find Uncle Bungle’s solution.

[enigma71]

Advertisements

6 responses to “Enigma 71: Some very cross numbers

  1. Jim Randell 16 March 2013 at 8:40 am

    This Python program runs in 34ms.

    from enigma import irange, split, printf
    
    # none of the digits is 0
    
    # "1-2-3 Not a multiple of 3 and of 5 and of 7"
    # so, it is a multiple of 3, 5 and 7, hence a multiple of 105
    for a in irange(1, 9):
      (n1, n2, n3) = split(a * 105, int)
      if 0 in (n1, n2, n3): continue
    
      # "3-6 An odd number"
      # so, it is an even number
      for n6 in (2, 4, 6, 8):
    
        # "4-5-6 The sum of the digits is greater than 5"
        # so, the sum is not greater than 5
        for n5 in irange(1, 4 - n6):
          for n4 in irange(1, 5 - (n5 + n6)):
    
            # "1-4-7 The sum of the digits is less than 19"
            # so the sum is not less than 19
            for n7 in irange(19 - (n1 + n4), 9):
    
              # "2-5-8 The sum of the digits is greater than n3 + n6"
              # so, the sum is not greater than n3 + n6
              for n8 in irange(1, (n3 + n6) - (n2 + n5)):
    
                # "7-8-9 The last digit is less than the sum of the first two"
                # so, n9 is not less than n7 + n8
                for n9 in irange(n7 + n8, 9):
              
                  printf("{n1} {n2} {n3} / {n4} {n5} {n6} / {n7} {n8} {n9}")
    

    Solution: Uncle Bungle’s solution is:

    Enigma 71 - Solution

    • Jim Randell 21 October 2015 at 2:34 pm

      Here’s a solution using the CrossFigure() solver from enigma.py (originally written for Enigma 1760). It runs in 60ms.

      from itertools import product
      from enigma import CrossFigure, irange, nconcat, printf
      
      # label the squares
      (s1, s2, s3, s4, s5, s6, s7, s8, s9) = irange(0, 8)
      
      # create the puzzle
      p = CrossFigure('?????????')
      
      # d digit numbers (with non-zero digits) that satisfy fn
      # (fn is passed the number and then the digits)
      def answers(d, fn):
        for ds in product(irange(1, 9), repeat=d):
          n = nconcat(ds)
          if fn(n, *ds):
            yield n
      
      # 1-2-3: "a multiple of 3 and of 5 and of 7"
      p.set_answer([(s1, s2, s3)], answers(3, lambda n, d1, d2, d3: n % (3 * 5 * 7) == 0))
      
      # 4-5-6: "the sum of the digits is not greater than 5"
      p.set_answer([(s4, s5, s6)], answers(3, lambda n, d1, d2, d3: not(d1 + d2 + d3 > 5)))
      
      # 7-8-9: "the last digit is not less than the sum of the first two"
      p.set_answer([(s7, s8, s9)], answers(3, lambda n, d1, d2, d3: not(d3 < d1 + d2)))
      
      # 1-4-7: "the sum of the digits is not less than 19"
      p.set_answer([(s1, s4, s7)], answers(3, lambda n, d1, d2, d3: not(d1 + d2 + d3 < 19)))
      
      # 2-5-8: "the sum of the digits is not greater than the sum of the digits of 3 down (3-6)"
      # (this is implemented as a check on the completed grid)
      p.set_check(lambda g: not(sum(int(g[i]) for i in (s2, s5, s8)) > sum(int(g[i]) for i in (s3, s6))))
      
      # 3-6: "not an odd number"
      p.set_answer([(s3, s6)], answers(2, lambda n, d1, d2: not(n % 2 == 1)))
      
      # find solutions
      for s in p.solve():
        printf("{s[0]} {s[1]} {s[2]} / {s[3]} {s[4]} {s[5]} / {s[6]} {s[7]} {s[8]}")
      
  2. Vítor Junqueira 20 October 2015 at 3:47 pm

    Just for the record, let me point that there may be a slight glitch at the hints, namely the 1-across. 945 is the unique solution where 1-A is both a multiple of 3, 5 and 7. But the negation of “A and B and C” should be “A or B or C” (uncle Bungle would still be wrong if he answered a multiple of 5 who isn’t a multiple of 7, for instance), but in that case there would be plenty of solutions…

    • Jim Randell 20 October 2015 at 8:03 pm

      I viewed the clue of 1-2-3 as “not(a multiple of 3 and of 5 and of 7)” so the negation is “a multiple of 3 and of 5 and of 7”. Which give us a unique solution that is the same as the published solution. So I think this is probably what the setter intended.

      If you view it as “not(a multiple of 3) and not(a multiple of 5) and not(a multiple of 7)” then the negation is indeed “(a multiple of 3) or (a multiple of 5) or (a multiple of 7)”, and there are 21 solutions. The top row being one of: 912, 915, 917, 918, 924, 925, 927, 933, 935, 936, 938, 939, 945, 948, 955, 957, 959, 966, 969, 978, 999.

      • Vítor Junqueira 21 October 2015 at 4:04 pm

        Quite right, Jim. Your explanation settles this question quite well. With that, I can’t see anything else than “not (a multiple of 3, 5 and 7)” (with the condition being only one and the three numbers being just a list of numbers not a list of conditions). Thank you.

  3. geoffrounce 28 August 2016 at 9:36 am
    % A MiniZinc solution
    include "globals.mzn";
    
    % ABC 123  
    % DEF 456
    % GHI 789
    
    var 1..9:A; var 1..9:B; var 1..9:C; 
    var 1..9:D; var 1..9:E; var 1..9:F; 
    var 1..9:G; var 1..9:H; var 1..9:I;
    
    % Cross Figure Clues  
    var 111..999 : A123;
    var 111..999 : A456;
    var 111..999 : A789;
    var 111..999 : D147;
    var 111..999 : D258;
    var 111..999 : D369;
    var 11.. 99 : D36;
    
    % ACROSS CLUES
    % Wrong clue 1-2-3 - is not a multiple of 3 and of 5 and of 7.
    constraint A123 = 100*A + 10*B + C /\
    A123 mod 7 == 0 /\ A123 mod 5 ==  0 /\ A123 mod 3 == 0;
    
    % Wrong clue 4-5-6 - The sum of the digits is greater than 5.
    constraint A456 = 100*D + 10*E + F /\ D+E+F <= 5;
    
    % Wrong clue 7-8-9 - The last digit is less than the sum of the first two.
    constraint A789 = 100*G + 10*H + I /\ I >= G+H;
    
    % DOWN CLUES
    % Wrong Clue 1-4-7  The sum of the digits is less than 19.
    constraint A+D+G >= 19;
    
    % Wrong Clue 2-5-8  The sum of the digits is greater than the sum of digits of 3 down.
    constraint  B+E+H <= C+F+I;
    
    % Wrong Clue 3-6  An odd number.
    constraint (10*C + F) mod 2 == 0;
    
    solve satisfy;
    
    output[ "Solution: " ++ "\n" ++ show(A123) ++ "\n" ++ show(A456) ++ "\n" ++ show(A789)];
    
    % Solution:
    % 945
    % 212
    % 819
    % Finished in 79msec
    %
    

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: