Enigmatic Code

Programming Enigma Puzzles

Enigma 1633: Same perfect square

From New Scientist #2799, 12th February 2011 [link]

Harry, Tom and I were each looking to find two 2-digit positive integers which each were the product of two primes and whose difference was also the product of two primes, the six primes all being different.

We each found a different valid solution; in each solution the sum of the two integers was a perfect square. For Harry and Tom it was the same perfect square.

What were my two integers?

[enigma1633]

Advertisements

One response to “Enigma 1633: Same perfect square

  1. jimrandell 13 December 2011 at 9:44 am

    This Python program runs in 34ms.

    from enigma import multiply, factor, is_square, Primes
    from itertools import combinations
    
    # find primes < 50
    primes = Primes(50)
    
    # find 2-digit products
    products = []
    for s in combinations(primes, 2):
      n = multiply(s) # n is the product of two different primes
      if not(9 < n < 100): continue # and is two-digit
      products.append((n, s))
    
    # select pairs of the 2-digit products
    for s in combinations(products, 2):
      t = s[0][0] + s[1][0] # sum
      if not is_square(t): continue
      d = abs(s[1][0] - s[0][0]) # difference
      f = factor(d)
      if not(len(f) == 2 and f[0] != f[1]): continue
      if not(len(set(f).union(s[0][1], s[1][1])) == 6): continue
      print(t, s, d, f)
    

    Solution: My integers are 74 and 95.

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: