Enigmatic Code

Programming Enigma Puzzles

Enigma 1617: More wanted

From New Scientist #2782, 16th October 2010 [link]

I have written down a three-by-three magic square containing the digits 1 to 9. I have then substituted letters for digits so that two of the rows of the square look like ROW and SUM. Furthermore, taking six digits from the square to form a six-figure perfect square, and then using the same letter substitution, I get SQUARE.

What is the numerical value of MORE?

[enigma1617]

Advertisements

One response to “Enigma 1617: More wanted

  1. jimrandell 27 December 2011 at 2:57 pm

    The following Python program runs in 30ms.

    # valid triples in the magic square
    t = {
      1: { 5: 9 },
      2: { 7: 6, 9: 4 },
      3: { 5: 7 },
      4: { 3: 8, 9: 2 },
      5: {},
      6: { 1: 8, 7: 2 },
      7: { 5: 3 },
      8: { 1: 6, 3: 4 },
      9: { 5: 1 }
    }
    
    # find all possible 6 digit squares composed of non-repeating non-zero digits
    for i in range(316, 1000):
      s = i * i
      d = set(list(str(s)))
      if len(d) < 6: continue
      if '0' in d: continue
    
      (S, Q, U, A, R, E) = map(int, list(str(s)))
    
      # Q + A + E = 15 (as it's the final row)
      if Q + A + E != 15: continue
    
      # determine M
      if U in t[S]:
        M = t[S][U]
        if M in (Q, A, R, E): continue
    
        # determine possible values for O
        Os = set(t[R].keys()).difference((S, Q, U, A, R, E, M))
    
        for O in Os:
          # determine W
          W = t[R][O]
          
          print("MORE={M}{O}{R}{E} [ROW={R}{O}{W}, SUM={S}{U}{M}, SQUARE={S}{Q}{U}{A}{R}{E} ({i}^2)]".format(**vars()))
    

    Solution: MORE = 7941.

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: