Enigmatic Code

Programming Enigma Puzzles

About

The purpose of this site is to share and discuss programmatic solutions to New Scientist‘s Enigma puzzles.

I’ve been writing programs to solve the puzzles for a few years now, originally in Perl and more recently in Python, as a way to have a weekly programming challenge. Some of my Python programs use useful routines from my enigma.py library.

The purpose of the challenge (for me) is not necessarily to produce the shortest possible program, or the fastest executing, but to produce a nice readable solution that can been seen to be right by looking at it, and executes in a reasonable time (usually less than 10 seconds, but essentially shorter than it would take to write (and debug) a more complicated solution). I usually try to write a program that produces a constructive solution and verifies all the conditions stated in the puzzle. And if the program can be used to solve a class of similar puzzles (or easily modified to do this) then that’s even better.

Enigma puzzles ran in New Scientist magazine from February 1979 up to December 2013, I add puzzles to the site typically every Monday and Friday, alternating the oldest unpublished puzzle with the newest unpublished puzzle.

The easiest way to keep track of puzzles is to subscribe to the RSS feed for the site, but I also post announcements of the puzzles to the Google+ Enigmatic Code community as they are made available on the site, and to the Facebook Enigmatic Code page.

Feel free to join in, either by leaving a comment (with a program if you like), or by rating puzzles or just “liking” them. Any kind of feedback is useful in encouraging me to keep the site going!

Jim Randell


Notes:

  • I am not affiliated with New Scientist magazine in any way (other than subscribing to it), nor am I paid for running this site.
  • This is an English language site so I’m only able to accept comments in English. Sorry. But you can use whatever programming language you like when posting code.
  • Feel free to also post analytic (non-programmed) solutions.
  • Comments are moderated and any that stray from civil discussion of Enigma puzzles will be edited or removed. When you first comment on the site (and sometimes at other times) comments are held for moderation so won’t appear immediately on the site, after that they usually will, but occasionally WordPress’s spam-filtering will hold up messages. I try to check the messages held for moderation at least once a day.
  • The site is hosted on WordPress which has limited support for preview or editing of comments, so bear that in mind before hitting “Post”. But if you wish to remove or update a comment let me know and I’ll sort it out. (And if you’ve got any suggestions for a better place to host the site, let me know).
  • See the Notes page for some tips on posting to the site.
  • The text of the original puzzles is copyright New Scientist and/or the original authors of the puzzles. They are reproduced on this site (with links where possible) in order to facilitate discussions of their solutions. Copyright of the comments remains with the original authors of the comments.
Advertisements

3 responses to “About

  1. Tessa Fullwood 24 October 2014 at 5:27 pm

    I just rated 20 enigmas, 2 of which I gave 5 stars to!

  2. Bryden Gage 27 September 2015 at 11:49 pm

    hey Jim,

    I’m trying to get my students into these types of logic puzzles. They’re grade 8s, so starting with very basic stuff….i.e. AA + B = BCC etc….MMy dad once made a whole wack load of these for his students when he was a teacher, and I’m looking for a resource that might have them made up. Any ideas?
    Thanks!
    Bryden (bryden_gage@hotmail.com)

    • Jim Randell 28 September 2015 at 5:26 pm

      If you search for “cryptarithm” or “alphametic” you can find people who have compiled lists of these puzzles. For example at the following sites:

      http://cryptarithms.awardspace.us/puzzles.html
      http://www.tkcs-collins.com/truman/alphamet/alphamet.shtml

      If you are familiar with programming you can use the SubstitutedSum() class from the enigma.py library to solve these:

      $ python
      >>> from enigma import SubstitutedSum as Sum
      >>> Sum(['SEND', 'MORE'], 'MONEY').go()
      SEND + MORE = MONEY
      9567 + 1085 = 10652 / D=7 E=5 M=1 N=6 O=0 R=8 S=9 Y=2
      >>> 
      

      It will print out a line for each solution that it finds.

      Given a list of words you can also use SubstitutedSum() to generate these puzzles.

      Here’s a program which looks for words from ZERO, ONE, TWO, …, TWENTY, THIRTY, FORTY, …, NINETY, and generates puzzles from them:

      from itertools import combinations_with_replacement
      from enigma import SubstitutedSum, int2words, irange, first, printf
      
      # target words
      ns = set(irange(0, 20)).union(set(irange(0, 90, step=10)))
      words = list(int2words(i).upper() for i in ns)
      
      # number of summands
      n = 2
      
      # choose the summands
      for ss in combinations_with_replacement(words, n):
        # choose the total
        for t in words:
      
          # try to solve the puzzle
          try:
            p = SubstitutedSum(ss, t)
            rs = first(p.solve(), 2)
          except AssertionError:
            continue
      
          # report puzzles with a unique solution
          if len(rs) == 1:
            printf("[{p.text}]")
            p.solution(rs[0])
            printf()
      

      It finds puzzles with unique solutions.

      Here are the ones it finds with two summands (without solutions, in case you want to try them):

      THREE + FOUR = EIGHTY
      THREE + EIGHTY = TWELVE
      FOUR + FORTY = TWELVE
      FIVE + FIVE = SEVEN
      FIVE + SEVEN = THIRTY
      FIVE + SEVEN = NINETY
      FIVE + ELEVEN = THIRTY
      FIVE + TWELVE = NINETY
      FIVE + THIRTY = ELEVEN
      FIVE + SIXTY = ELEVEN
      SEVEN + SEVEN = THIRTY
      SEVEN + SEVEN = NINETY
      EIGHT + TWELVE = EIGHTY
      EIGHT + TWENTY = ELEVEN
      EIGHT + EIGHTY = TWELVE
      NINE + NINE = EIGHT
      NINE + NINE = FIFTY
      TWELVE + TWELVE = EIGHTY
      TWELVE + TWELVE = NINETY
      TWELVE + TWENTY = FIFTEEN
      TWELVE + TWENTY = SIXTEEN
      TWELVE + SEVENTY = SIXTEEN
      TWELVE + NINETY = FIFTEEN
      THIRTY + NINETY = SIXTEEN
      FORTY + FORTY = TWELVE
      SIXTY + SIXTY = TWELVE
      SIXTY + NINETY = ELEVEN
      EIGHTY + EIGHTY = FIFTEEN
      EIGHTY + EIGHTY = SIXTEEN
      EIGHTY + NINETY = FIFTEEN
      EIGHTY + NINETY = SIXTEEN

      You can change the definition of n at line 9 to find sums with more than two summands.

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: