Enigmatic Code

Programming Enigma Puzzles

Enigma 1512: All square

From New Scientist #2674, 20th September 2008

I started with a list of numbers. Then I coded them using letters for digits, with different letters consistently used for different digits. In this way the list became:

ARE
ANY
NOS
HERE
SQUARE

If you knew how many of the original numbers were square, then it would be possible to find all the numbers.

Find the value of the number that is YOURS.

[enigma1512]

Advertisements

One response to “Enigma 1512: All square

  1. Jim Randell 30 September 2012 at 8:37 pm

    I have incorporated concat() from my solution to Enigma 1515 into the enigma.py library as nconcat(). I’ve used it in the following Python program, which runs in 5.8s (using PyPy).

    from itertools import permutations
    from enigma import nconcat, irange, is_square, printf
    
    # count how many assignments give the same number of squares
    r = [0] * 6
    # and record the first assignment in each case (as an example)
    a = [None] * 6
    # leading digits (could also include Y here)
    ds = set(irange(1, 9))
    for (A, H, N, S) in permutations(ds, 4):
      ds0 = ds.difference((A, H, N, S)).union([0])
      # remaining digits
      for (E, O, Q, R, U, Y) in permutations(ds0, 6):
        # what are the numbers?
        ns = list(nconcat(*x) for x in ((A, R, E), (A, N, Y), (N, O, S), (H, E, R, E), (S, Q, U, A, R, E)))
        # how many are square?
        s = len(list(n for n in ns if is_square(n)))
        if r[s] == 0:
          a[s] = (A, H, N, S, E, O, Q, R, U, Y)
        r[s] += 1
    
    for i in irange(0, 5):
      printf("[{i} squares => {n}]", n=r[i])
      if r[i] != 1: continue
      (A, H, N, S, E, O, Q, R, U, Y) = a[i]
      printf("YOURS = {Y}{O}{U}{R}{S} [{i} squares, ARE={A}{R}{E} ANY={A}{N}{Y} NOS={N}{O}{S} HERE={H}{E}{R}{E} SQUARE={S}{Q}{U}{A}{R}{E}]")
    

    Solution: YOURS = 41326.

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: