Enigmatic Code

Programming Enigma Puzzles

Enigma 1304: Some obvious facts

From New Scientist #2462, 28th August 2004

You know that:

NINETY is divisible by 9.
TEN is 1 more than a perfect square divisible by 9.
There are SIX perfect squares between TEN and NINETY.

But in those displayed words each capital letter consistently represents a digit, with different letters used for different digits.

Which number should be SENT?

[enigma1304]

Advertisements

2 responses to “Enigma 1304: Some obvious facts

  1. Jim Randell 4 August 2014 at 7:22 am

    This Python program runs in 32ms.

    from itertools import count
    from enigma import irange, split, nconcat, sqrt, intc, intf, printf
    
    digits = set(irange(0, 9))
    
    # consider squares
    for i in count(1):
      s = i ** 2
      # the square must be divisible by 9
      if s % 9 > 0: continue
      # and TEN = s + 1, must be 3 digits
      TEN = s + 1
      if TEN < 100: continue
      if TEN > 999: break
      (T, E, N) = split(TEN, int)
      if N == 0: continue
      ds1 = digits.difference((T, E, N))
      if len(ds1) != 7: continue
    
      # NINETY is divisible by 9, so N+I+N+E+T+Y is
      for I in ds1:
        Y = 9 - (N + I + N + E + T) % 9
        ds2 = ds1.difference((I, Y))
        if len(ds2) != 5: continue
        NINETY = nconcat(N, I, N, E, T, Y)
    
        # count squares between TEN and NINETY
        SIX = intf(sqrt(NINETY)) - intc(sqrt(TEN)) + 1
        if not(99 < SIX < 1000): continue
        (S, I2, X) = split(SIX, int)
        if I2 != I: continue
        ds3 = ds2.difference((S, X))
        if len(ds3) != 3: continue
    
        SENT = nconcat(S, E, N, T)
        printf("SENT={SENT} [TEN={TEN} NINETY={NINETY} SIX={SIX} {ds3}]")
    

    Solution: SENT = 3019.

    • Jim Randell 7 February 2017 at 2:19 pm

      We can also solve this puzzle using the general alphametic solver (SubstitutedExpression() in the enigma.py library).

      This run-file executes in 94ms.

      #!/usr/bin/env python -m enigma -r
      
      # solver to use
      SubstitutedExpression
      
      # solver parameters
      --answer="SENT"
      
      # expressions to solve
      "NINETY % 9 = 0"
      "is_square(TEN - 1) % 3 = 0"
      "isqrt(NINETY) - isqrt(TEN) = SIX"
      

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: