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. (If you would like to also use it, and let me know if you have any problems, that would be appreciated).

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”. (I recommend composing the comment offline, and if it goes wrong you can email me the original version and I can amend the comment accordingly). 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.
Advertisement

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

  5. Tony McArdle 24 February 2021 at 5:06 am

    Hi Jim
    I’ve been meaning to write to you for a while now. I’ve been following your work with the New Scientist puzzles and using them to teach myself Python. At the start, I depended heavily on your work, but I have moved to doing many of the puzzles by myself and checking my results with yours. I’m really impressed with your output and appreciate your help (even though unbeknownst to you) for my Python education.
    I am registered to receive your regular emails.
    I’m doing these puzzles, and learning Python, purely for enjoyment, as I guess you are too.
    Thank you so much.
    Regards
    Tony McArdle

  6. Tony McArdle 6 August 2021 at 4:28 am

    Hi Jim,
    I received an email from you for Tantalizer 230: Women’s lib, but the link does not work. I have tried several times. I managed to find the “original” online and also the solution. If you want I could email them (jpgs) to you.
    Keep up the great work. (I am already on your mailling list)
    Thanks
    Tony McArdle

    • Jim Randell 9 August 2021 at 5:17 pm

      Hi Tony,
      I have transcribed all Tantalizer puzzles back to Tantalizer 181 (using the Google Books archive of New Scientist magazines), and am slowly working through posting them. I probably hit “Publish” instead of “Save” when I was transcribing the puzzle if you got an email, but I can bring it forward if you’ve been looking at it. (Otherwise I am just posting the most recent unposted puzzle each time a Tantalizer is due).

      • Tony McArdle 10 August 2021 at 5:16 am

        Thanks Jim. I managed to see the puzzle and the solution (via Google) so I don’t need anything more. I just wanted to let you know.
        Thanks again for all your posts. I’m having great fun working through the puzzles (selected ones) and solving them (or trying to).
        Regards
        Tony

  7. alkisp 4 July 2022 at 9:54 pm

    Hi! How can I post code (solution) for Puzzle #54?

    • Jim Randell 4 July 2022 at 10:03 pm

      Hi,

      Code can be included in comments like this:

      [code language="python"]
      <code goes here>
      [/code]

      Syntax highlighting for other languages is available (see [link], or use language="text" for no highlighting).

      Unfortunately, WordPress doesn’t have the ability for you to edit comments once they are posted, so do give it a read through before pressing “Post Comment”.

  8. alkisp 13 July 2022 at 7:33 am

    Congratulations, Jim! Great work and site! 👍

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 )

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: