Enigmatic Code

Programming Enigma Puzzles

Enigma 1394: Squares and triangles

From New Scientist #2554, 3rd June 2006

Any number which is the sum of all the perfect squares from 1 to x² is called a square pyramidal number (such as 1, 5, 14, 30, 55). Any number which is the sum of the first x triangular numbers is called a tetrahedral number (such as 1, 4, 10, 20, 35). Within each of the following two statements digits have been consistently replaced by capital letters, different letters being used for different digits. But the two statements are entirely distinct – a letter need not have the same value in one statement as in the other.

Statement 1: ONE and FIVE are both odd square pyramidal numbers.

Statement 2: ONE is an odd tetrahedral number and FOUR is an even tetrahedral number.

Find the numbers represented by: (a) ONE and FIVE in Statement 1, and (b) ONE and FOUR in Statement 2.

This is the 500th Enigma puzzle published to the site. Hooray!

There is now complete coverage from June 2006 to the most recent puzzle (i.e. the last seven years), and also Classic puzzles from the start of Enigma in February 1979 up to August 1981. The most recent puzzle published is Enigma 1765, so this puts us at just over 28% of all Enigma puzzles ever published available on the site.

[enigma1394]

Advertisements

6 responses to “Enigma 1394: Squares and triangles

  1. Jim Randell 8 September 2013 at 10:08 am

    This Python program runs in 35ms.

    from collections import defaultdict
    from itertools import count
    from enigma import is_duplicate, T, printf
    
    # generate square pyramidal numbers
    # we accumulate odd SPs with no repeated digits
    (SP, sp) = (defaultdict(list), 0)
    for i in count(0):
      sp += i * i
      if sp > 9999: break
      if sp % 2 == 0: continue
      s = str(sp)
      if is_duplicate(s): continue
      SP[len(s)].append(s)
    
    # For part (a) we find a 3-digit SP matching ONE
    for ONE in SP[3]:
      (O, N, E) = ONE
      # and a 4-digit SP matching FIVE
      for FIVE in SP[4]:
        if FIVE[-1] != E or O in FIVE or N in FIVE: continue
        printf("(a) ONE={ONE} FIVE={FIVE}")
    
    
    # generate tetrahedral numbers
    # accumulate ones with no repeated digits, and the correct parity
    (tetra, t) = (defaultdict(list), 0)
    for i in count(0):
      t += T(i)
      if t > 9999: break
      s = str(t)
      if is_duplicate(s): continue
      if (t + len(s)) % 2 == 1: continue
      tetra[len(s)].append(s)
    
    # for part (b) we need a 3-digit tetra matching ONE
    for ONE in tetra[3]:
      (O, N, E) = ONE
      # and a 4-digit tetra matching FOUR
      for FOUR in tetra[4]:
        if FOUR[1] != O or N in FOUR or E in FOUR: continue
        printf("(b) ONE={ONE} FOUR={FOUR}")
    

    Solution: (a) ONE = 285, FIVE = 3795; (b) ONE = 165, FOUR = 7140.

  2. Naim Uygun 8 September 2013 at 12:10 pm

    I found the answers by observing the output of this program:

    sp=[x*x for x in range(1,32)]
    st=[x*(x+1)//2 for x in range(1,40)]
    print("\nStatement 1: ONE and FIVE are both odd square pyramidal numbers")
    print("Choices for Statement 1")
    
    #STATEMENT 1 Answer: ONE=285, FIVE=3795
    for i in range(0,len(sp)):
        n=sum(sp[0:i])
        if 99<n<1000 and n%2==1:
            print("ONE=",n)
        if 999<n<10000 and n%2==1:
            print("FIVE=", n)
    print("\nStatement 2: ONE is an odd tetrahedral number and")
    print("FOUR is an even tetrahedral number.")
    print("Choices for Statement 2")
    
    #STATEMENT 2 Answer: ONE=165 FOUR=7140
    for i in range(0,len(st)):
        n=sum(st[0:i])
        if 99<n<1000 and n%2 != 0:
            print("ONE=",n)
        if 999<n<10000 and n%2==0:
             print("FOUR=",n)
    
  3. ahmet çetinbudaklar 8 September 2013 at 1:55 pm

    Dear Jim:

    This is the most comprehensive longest list of puzzles I have ever seen in the internet so far.
    May I reiterate my sincere appreciation of your delicate work with a lot of passion and diligent attention from your end.
    We have 1765-500=1215 puzzles left!
    Best wishes to you

    ahmet

    • Jim Randell 9 September 2013 at 12:41 pm

      Thanks. So far I’ve been able to track down most of the puzzles I’ve published from online sources, but I estimate there are around 600 that I’ll need to find a copy of the New Scientist in question for. So I’ll be making a trip to Bristol Central Library soon to see if they can help me.

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: