Enigmatic Code

Programming Enigma Puzzles

Enigma 267: Just one at a time

From New Scientist #1414, 26th July 1984 [link]

I have in mind a five-figure number. It satisfies just one of the statements in each of the triples below.

The sum of its digits is not a multiple of 6.
It is divisible by a number whose units digit is 3.
Its middle digit is odd.

The sum of its digits is odd.
It has a factor which is not palindromic.
It is not divisible by 1001.

It has two or more different prime factors.
It is not a perfect square.
It is not divisible by 5.

What is the number?

Due to industrial action New Scientist was not published for 5 weeks between 19th June 1984 and 19th July 1984.

This brings the total number of Enigma puzzles available on the site to 804, just over 45% of all Enigma puzzles published.

[enigma267]

5 responses to “Enigma 267: Just one at a time

  1. Jim Randell 22 March 2015 at 9:36 am

    I think the puzzle is flawed, in that there are multiple solutions.

    This program examines all 5 digit numbers. It runs in 1.7s.

    from enigma import irange, split, divisors, prime_factor, is_square, printf
    
    # consider 5-digit numbers
    for n in irange(10000, 99999):
    
      # ns = digits
      ns = split(n, int)
      # s = digit sum
      s = sum(ns)
      # ds = divisors
      ds = divisors(n)
      # fs = prime factors
      fs = tuple(p for (p, _) in prime_factor(n))
    
      # count the number of true statements in the first triple
      t1 = (
        # "the sum of its digits is not a multiple of 6"
        (s % 6 > 0),
        # "it is divisible by a number whose units digit is 3
        any(d % 10 == 3 for d in ds),
        # "its middle digit is odd"
        (ns[2] % 2 == 1),
      )
      if t1.count(True) != 1: continue
    
      # count the number of true statements in the second triple
      t2 = (
        # "the sum of its digits is odd"
        (s % 2 == 1),
        # "it has a divisor which is not palindromic"
        any(s != s[::-1] for s in map(str, ds)),
        # "it is not divisible by 1001
        (n % 1001 > 0),
      )
      if t2.count(True) != 1: continue
    
      # count the number of true statements in the third triple
      t3 = (
        # "it has two or more different prime factors"
        (len(fs) > 1),
        # "it is not a perfect square"
        (is_square(n) is None),
        # "it is not divisible by 5"
        (n % 5 > 0),
      )
      if t3.count(True) != 1: continue
    
      printf("{n} {t1} {t2} {t3}")
    

    Solution: The number is either 10201 or 14641.

    The published solution is 10201.

    I think the minimal way to fix this puzzle is to change the 6th statement to be:

    It is not divisible by 101.

    While that does yield a unique solution to the problem it is clearly not the one the setter had in mind, as 10201 is eliminated (because it is divisible by 101), leaving 14641 as the only possible solution.

    • geoffrounce 22 March 2015 at 10:27 am
      
      from enigma import is_square,factor, is_prime, divisors 
      
      for n in range(10000,100000):
          n_str = str(n)
          n1, n2, n3 = int(n_str[0]), int(n_str[1]), int(n_str[2])
          n4, n5 = int(n_str[3]), int(n_str[4])
          n_sum = n1 + n2 + n3 + n4 + n5
          div = divisors(n)
          
          # check 1st set of triple conditions
          cond1 = 0
          if n_sum % 6 != 0 : cond1 += 1
          if n3 % 2 == 1 : cond1 += 1
          if any(x % 10 == 3 for x in div): cond1 += 1
          if cond1 != 1:
              continue
                  
          # check 2nd set of triple conditions
          cond2 = 0     
          if n_sum % 2 == 1: cond2 += 1
          if any(str(x) != str(x)[::-1] for x in div): cond2 += 1
          if n_sum % 1001 != 0: cond2 += 1
          if cond2 != 1:
              continue
              
          # check 3rd set of triple conditions
          cond3 = 0
          if len(set(factor(n))) >= 2: cond3 += 1
          if is_square(n) == None: cond3 += 1
          if n % 5 != 0: cond3 += 1
          if cond3 != 1:
              continue
           
          print(n)
      
      
    • Naim Uygun 22 March 2015 at 5:40 pm

      Hi Jim,
      Why not the number 36481 can not be an answer, too? Thanks.

      • Jim Randell 22 March 2015 at 5:53 pm

        For 36481 two of the statements in the second triple are true, we need numbers that have exactly one true statement in each triple.

        2.1) The sum of the digits is 22, so this statement is false.
        2.2) The divisors are 1, 191 and 36481, so (unless we exclude the number itself) then it does have a divisor which is not palindromic, so this statement is true.
        2.3) It is not divisible by 1001, so this statement is true.

        If we took statement 2.2 to exclude the actual number itself (so only consider “proper divisors”), then 36481 would be another potential solution (along with the two we’ve already found).

  2. Naim Uygun 22 March 2015 at 8:10 pm
    def asal(n):
        if n<=1: return False
        if n in [2,3]: return True
        if n%2==0  or n%3==0 : return False
        x=int((n**0.5+1)/6.0+1)
        for b in range(1,x):
            if n%(6*b-1)==0:
                return False
            if n %(6*b+1)==0:
               return False
        return True
    
    def kare(q):
        n=int(q)
        h = n & 0xF    
        if (h > 9) :
            return False   
        if h in [0,1,4,9]:
            t =int(n**0.5)
            return (t*t == n)        
        return False
    
    def  digitsum(n):
        s=list(str(n))
        D=[int(s[i]) for i in range(0,5)]
        return sum(D)
    
    def div6(n):
        if n%6 == 0:return False
        return True
    
    def unit3(n):
        for i in range(3,n):
            if i%10 != 3: continue
            q,r=divmod(n,i)
            if r==0: return True
        return False
    
    def mid(n):
        s=str(n)
        if int(s[2])%2 == 0 : return False
        return True
    
    def digod(n):
        x=digitsum(n)
        if x%2 == 0: return False
        return True
    
    def pal(n):
        for i in range(n,1,-1):        
            r=n%i
            if r != 0: continue
            s=str(i)
            if s != s[::-1]: return True
        return False    
         
    def div1001(n):
        if n%1001 != 0: return True
        return False
    
    def twomore(n):
        count=0
        for i in range(2, n):
            if asal(i)==False: continue
            if n%i==0 :           
               count += 1
               if count>=2: return True
        return False
    
    def issquare(n):
        if kare(n) == True: return False
        return True
    
    def div5(n):
        if n%5 != 0: return True
        return False
    
    count=0
    for n in range(10000 ,100000):   
        L1=[ div6(n),unit3(n),mid(n)]
        if L1.count(True) != 1: continue
       
        L2=[ digod(n) , pal(n),div1001(n)]
        if L2.count(True) != 1: continue
       
        L3=[twomore(n),issquare(n),div5(n)]
        if L3.count(True) != 1: continue
        count += 1
        print(count,")",n,L1,L2,L3)
        """
        Output:
        1 ) 10201 [True, False, False] [False, False, True] [False, False, True]
        2 ) 14641 [True, False, False] [False, False, True] [False, False, True]
        """
       

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: