Enigmatic Code

Programming Enigma Puzzles

Enigma 1141: Powers of two

From New Scientist #2297, 30th June 2001 [link]

In the following statements digits have been consistently replaced by capital letters, different letters being used for different digits:

TWO is a prime number,
FOUR is a perfect square,
EIGHT is a [perfect] cube.

You should assume that neither TWO nor FOUR nor EIGHT starts with a zero.

Find the number represented by EIGHT.

[enigma1141]

Advertisements

2 responses to “Enigma 1141: Powers of two

  1. Jim Randell 14 November 2016 at 8:28 am

    This puzzle can be solved directly by the SubstitutedExpression() solver in the enigma.py library in 155ms, without the need to write a program.

    % python -m enigma SubstitutedExpression --answer="EIGHT" "is_prime(TWO)" "is_square(FOUR)" "is_cube(EIGHT)"
    (is_prime(TWO)) (is_square(FOUR)) (is_cube(EIGHT))
    (is_prime(503)) (is_square(1369)) (is_cube(42875)) / E=4 F=1 G=8 H=7 I=2 O=3 R=9 T=5 U=6 W=0 / 42875
    (is_prime(509)) (is_square(1936)) (is_cube(42875)) / E=4 F=1 G=8 H=7 I=2 O=9 R=6 T=5 U=3 W=0 / 42875
    EIGHT = 42875 [2 solutions]
    

    Solution: EIGHT = 42875.

    There are two possible values for TWO and FOUR: either (TWO, FOUR) = (503, 1369) or (TWO, FOUR) = (509, 1936).

  2. Brian Gladman 14 November 2016 at 11:48 pm
    from itertools import count, permutations
    from number_theory import is_prime
    
    cubes = (str(x ** 3) for x in range(22, 47))
    for p in (x for x in cubes if len(x) == len(set(x))):
      E, I, G, H, T = (int(x) for x in p)
      
      for q in permutations(set('0123456789').difference(p)):
        F, O, R, U, W = (int(x) for x in q)
        
        FOUR = 1000 * F + 100 * O + 10 * U + R
        TWO = 100 * T + 10 * W + O
        if F and int(FOUR ** 0.5 + 0.5) ** 2 == FOUR and is_prime(TWO):
          EIGHT = 10000 * E + 1000 * I + 100 * G + 10 * H + T
          print('EIGHT = {} (TWO = {}, FOUR = {})'.format(EIGHT, TWO, FOUR))
    

    Using my number theory library.

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: