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, or to sign up for email notifications, but I also post announcements of the puzzles to the Facebook Enigmatic Code page as they are made available on the site.

If you use the site as a source of puzzles please include a link back to the puzzle on this site.

Feel free to join in, either by leaving a comment (with a program if you like), or by rating puzzles or just “liking” them. If you want to leave a general comment about the site, please do so below. 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 or notes of general interest.
  • 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.

8 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.

  3. webunit80 29 October 2019 at 4:02 pm

    Apologies if I’m posting this comment on the wrong page but I have a question about alphametic puzzles like the well-known SEND+MORE=MONEY puzzle. These are quite common in ENIGMA’s. My question is: Are all alphametics solvable WITHOUT trial and error? The obvious answer is No, but I’m not certain. If at least some alphametics require trial and error then it would justify the use of a computer program to do this task. However, I am in no way suggesting that justification is necessary for using the computer to solve alphametics or any ENIGMA puzzles. I, like most people on this site, enjoy writing programs to solve ENIGMA’s and that’s just fine – no justification necessary. Thanks for reading.

    • Jim Randell 30 October 2019 at 8:06 am

      @webunit80: Thanks for your comment.

      I think there is some element of trial and error in most alphametic puzzles. For example, in simple sums each column will give a constraint on the symbols used in that column (although for all but the rightmost column potential carries must be considered), so you can sometimes work out (or at least restrict) the values of some of the symbols based on that. But in the end, even with a restrictions on some of the symbols, you end up trying the possibilities and seeing if they work.

      I have written some programmatic solvers for alphametic puzzles that are available in the enigma.py Python library. [[ SubstitutedSum() ]] works on simple addition sums, and [[ SubstitutedExpression() ]] can be used in general Python expressions.

      • webunit80 30 October 2019 at 6:50 pm

        Thanks for the info and I’ll definitely check out your Python programs. I’ve written a few myself in another language that shall not be named, but I’d like to get more experience with Python.

  4. webunit80 1 November 2019 at 11:44 pm

    Jim, I was looking at the list of ENIGMA’s and I see that many do not have links (not underlined) even though they don’t indicate that they’re missing. What does this mean? Also, I have some of the puzzles noted as missing. I can send them to you.

    • Jim Randell 4 November 2019 at 9:42 am

      @webunit80: The puzzles that are listed, but do not currently have links on the “List of Enigma Puzzles” page are those that I have been able to source and transcribe, but are not yet posted to the site.

      I try to keep to a schedule of posting two Enigma puzzles every week. The lowest numbered unposted puzzle on Monday, and highest numbered unposted puzzle on a Friday. But if there is a particular puzzle you would like to see included on the site ahead of this schedule I can bring it forward.

      I have also been posting bonus puzzles on a Wednesday, usually taken from the Puzzle or Tantalizer series of puzzles that appeared in New Scientist before Enigma started. And now I also post the puzzles appearing in the current issues of New Scientist on a Saturday.

      There are currently 465 Enigma puzzles that remain to be posted on the site, and I have around 85 left to source (from 1996-1998). But I am being helped in the regard by a colleague who is able to send me images of the missing puzzles before I am due to post them. I am happy that I will get an almost complete archive of Enigma puzzles in this way, but if you have easy access to the missing puzzles (or sources for the few that remain outside this range marked [missing] or [incomplete]) that would be appreciated.

Leave a Reply to webunit80 Cancel reply

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: