Enigmatic Code

Programming Enigma Puzzles

Puzzle 84: A cross number

From New Scientist #1136, 4th January 1979 [link]

Puzzle 84

Across:

1. The sum of the digits is 10.
3. Digits all even.
4. Digits all odd, and each one is less than one before.

Down:

1. The second digit is greater than either of the other two.
2. A multiple of 3 Down.
3. The second digit is greater than the first one.

(One of these numbers is the same as another one reversed and there are no 0s).

This completes the archive of New Scientist puzzles published in 1979.

[puzzle84]

Advertisements

One response to “Puzzle 84: A cross number

  1. Jim Randell 11 January 2017 at 7:53 am

    There is a solver for crossfigure puzzles in the enigma.py library, but in this case it is faster to use the general SubstitutedExpression() solver.

    In the following program the crossfigure puzzle is solved using the SubstitutedExpression() solver, and then we inspect the answers to check that one answer is the reverse of one of the other answers.

    This Python program runs in 65ms

    #
    # consider the grid:
    #
    #   # A B
    #   C D E
    #   F G H
    #
    
    from enigma import SubstitutedExpression, irange, find, printf
    
    # solve the puzzle as a SubstitutedExpression problem
    p = SubstitutedExpression([
          # AB = "1 across: the sum of the digits is 10"
          "A + B = 10",
          # FGH = "4 across: each digits is less than the one before"
          "F > G",
          "G > H",
          # ADG = "1 down: The second digit is greater than the other two"
          "D > A",
          "D > G",
          # BEH = "2 down: A multiple of 3 down"
          "BEH % CF = 0",
          # CF = "3 down: The second digit is greater than the first one"
          "F > C"
        ],
        # digits are not necessarily distinct
        distinct='',
        # only digits 1-9 are used
        digits=irange(1, 9),
        # invalid digits assignments
        d2i={
          # CDE = "3 across: digits all even"
          1: 'CDE', 3: 'CDE', 5: 'CDE', 7: 'CDE', 9: 'CDE',
          # FGH = "4 across: digits all odd"
          2: 'FGH', 4: 'FGH', 6: 'FGH', 8: 'FGH',
        }
      )
    
    # solve the problem
    for s in p.solve():
      # accumulate the crossfigure answers
      answers = list(p.substitute(s, x) for x in ('AB', 'CDE', 'FGH', 'CF', 'ADG', 'BEH'))
      # one of the answers is the reverse of another
      if all(find(answers, x[::-1]) in (-1, i) for (i, x) in enumerate(answers)): continue
      # output the grid
      printf(" {answers[0]}\n{answers[1]}\n{answers[2]}\n")
    

    Solution: The completed cross figure puzzle is:

    puzzle-84-solution

    The answer to 1 down is the reverse of the answer to 2 down (and vice versa, of course).

    Without this condition there are 36 different solutions to the crossfigure puzzle.

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: