Enigmatic Code

Programming Enigma Puzzles

Enigma 1615: Slide enlarger

From New Scientist #2780, 2nd October 2010 [link]

ENIGMA represents a six-digit number in which the digits are all different and non-zero.

When EN slides from the front to the back, the resulting six-digit number, IGMAEN, is 20 per cent larger than ENIGMA.

What is ENIGMA?

[enigma1615]

Advertisements

2 responses to “Enigma 1615: Slide enlarger

  1. jimrandell 28 December 2011 at 4:22 pm

    This straightforward Python program runs in 175ms.

    from itertools import permutations
    from enigma import printf
    
    for (E, N, I, G, M, A) in permutations('123456789', 6):
      ENIGMA = int(''.join((E, N, I, G, M, A)))
      IGMAEN = int(''.join((I, G, M, A, E, N)))
      if 5 * IGMAEN != 6 * ENIGMA: continue
      printf("ENIGMA = {ENIGMA}, IGMAEN = {IGMAEN}")
    

    Solution: ENIGMA = 384615.

    • jimrandell 28 December 2011 at 4:26 pm

      This slightly modified version runs slightly faster (170ms).

      from itertools import permutations
      from enigma import printf
      
      for s in permutations('123456789', 6):
        ENIGMA = int(''.join(s))
        IGMAEN = int(''.join(s[2:] + s[:2]))
        if 5 * IGMAEN != 6 * ENIGMA: continue
        printf("ENIGMA = {ENIGMA}, IGMAEN = {IGMAEN}")
      

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: