Enigmatic Code

Programming Enigma Puzzles

Enigma 368: What’s the truth

From New Scientist #1517, 17th July 1986 [link]

Each of the following six statements is either true or false.

1. Statements 2 and 3 are both true or both false.
2. Exactly one of statements 4 and 5 is true.
3. Exactly one of statements 4 and 6 is true.
4. Exactly one of statements 1 and 6 is true.
5. Statements 1 and 3 are both true or both false.
6. Exactly one of statements 2 and 5 is true.

Which of the six statements are true?

[enigma368]

Advertisements

2 responses to “Enigma 368: What’s the truth

  1. Jim Randell 28 October 2016 at 8:26 am

    This Python program looks at all possible truth values for the statements. It runs in 28ms.

    from itertools import product
    from enigma import printf
    
    # check truth values are equivalent
    def check(a, b):
      return a == b
    
    # assign truth values to the six statements
    for ss in product((True, False), repeat=6):
      (s1, s2, s3, s4, s5, s6) = ss
    
      # see if the values match up with the statements
    
      # 1. "Statements 2 and 3 are both true or both false"
      if not check(s1, s2 == s3): continue
    
      # 2. "Exactly one of statements 4 and 5 is true"
      if not check(s2, s4 ^ s5): continue
    
      # 3. "Exactly one of statements 4 and 6 is true"
      if not check(s3, s4 ^ s6): continue
    
      # 4. "Exactly one of statements 1 and 6 is true"
      if not check(s4, s1 ^ s6): continue
    
      # 5. "Statements 1 and 3 are both true or both false"
      if not check(s5, s1 == s3): continue
    
      # 6. "Exactly one of statements 2 and 5 is true"
      if not check(s6, s2 ^ s5): continue
    
      # output the statements
      for (i, v) in enumerate(ss, start=1):
        printf("{i}: {v}")
      printf()
    

    Solution: Statements 2 and 5 are true.

  2. arthurvause 28 October 2016 at 4:57 pm

    A similar approach to Jim’s

    I have converted the statements from 1,..6 to 0,..,5 for the analysis, then back again for the final answer:

    from itertools import product
    
    for x in product([True,False],repeat=6):
      if (x[1]==x[2],x[3]!=x[4],x[3]!=x[5],x[0]!=x[5],x[0]==x[2],x[1]!=x[4])==x:
        print "statements", [i+1 for i in xrange(6) if x[i]] ,"are 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 )

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: