Enigmatic Code

Programming Enigma Puzzles

Tantalizer 1: Publish or perish

From New Scientist #550, 22nd June 1967 [link]

Kappa, Lambda, Mu and Omicron are at present uneasily seated in the Warden’s study at Jude’s College, awaiting summonses from the committee which will appoint one of them to the vacant Fellowship in Greek Literature. Each is hugging his only published work and each suspects that the post will go to the author of the longest, irrespective of all possible merit.

From their stilted but cunning conversation, the following facts have so far emerged:

Each book has a whole number of pages over 100.

Only Lambda’s book and Mu’s book have the same number of pages.

The total number of pages in all four books is 500.

Mu then asked Omicron whether the number of his (Omicron’s) pages was a perfect square. From Omicron’s answer Mu and Kappa made silent and independent deductions with impeccable logic. Mu deduced that Omicron’s book was the longest. And Kappa, who was not a perfect square, deduced that Omicron’s answer was not the truth.

How many pages are there in each man’s book?

This was the first Tantalizer puzzle published in New Scientist. It was accompanied by the following introduction:

This is the first of a series of logical puzzles compiled by Martin Hollis. No mathematical knowledge is required for their solution. A new puzzle will appear each week, and the answer will be printed in the following week’s issue.

[tantalizer1]

Advertisement

One response to “Tantalizer 1: Publish or perish

  1. Jim Randell 8 March 2023 at 11:15 am

    M knows his own number, and from O’s claim he can deduce that O has the largest number.

    K knows his own number, and can deduce the O’s claim is false.

    And from the intersection of the two sets of scenarios we can determine what the actual numbers must be.

    This Python program runs in 66ms. (Internal runtime is 5.2ms).

    Run: [ @replit ]

    from enigma import (defaultdict, irange, decompose, is_square_p, printf)
    
    def generate():
      # K, L, M, O are the number of pages over 100, K + L + M + O = 100
      # choose the number of pages for L and M
      for L in irange(1, 48):
        for (K, O) in decompose(100 - 2 * L, 2, increasing=0, sep=1, min_v=1):
          if K == L or O == L: continue
          (K_, L_, M_, O_) = (100 + K, 100 + L, 100 + L, 100 + O)
          yield (K_, L_, M_, O_, is_square_p(O_), (O_ > max(K_, L_, M_)))
    
    # collect possible allocations
    rs = list(generate())
    
    # map: (M, is_square_p(O)) -> <O is longest> -> <values>
    Md = defaultdict(lambda: defaultdict(list))
    for (K, L, M, O, sqO, mxO) in rs:
      Md[(M, sqO)][mxO].append((K, L, M, O))
    
    # look for keys that can only give O as the largest
    Ms = set()
    for (k, v) in Md.items():
      if v[True] and not v[False]:
        Ms.add(k)
    
    
    # map: K -> is_square_p(O) -> <values>
    Kd = defaultdict(lambda: defaultdict(list))
    for (K, L, M, O, sqO, mxO) in rs:
      Kd[K][sqO].append((K, L, M, O))
    
    # look for keys that only give one option for is_square_p(O)
    for (k, v) in Kd.items():
      for f in [False, True]:
        if v[f] and not v[not f]:
          # check for values with a viable (M, utterance for O)
          # where K is not a square
          for (K, L, M, O) in v[f]:
            if (M, not is_square_p(O)) in Ms and not is_square_p(K):
              printf("K={K} L={L} M={M} O={O}")
    

    Solution: Page counts are: Kappa = 156; Lambda = 121; Mu = 121; Omicron = 102.

    The only way M can deduce that O has the largest number of pages, is if M has 121, and O claims his number is a perfect square. Then M deduces O has 144 (and K has 114). However M has been misled by O’s claim.

    There are many values that K can have, and deduce O’s claim must be false. Only two of them coincide with “M = 121 and O is not a perfect square”.

    These are:

    K=156 L=121 M=121 O=102
    K=144 L=121 M=121 O=114

    But we are told K is not a perfect square, so we can eliminate the second of these, leaving a unique solution.

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 )

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: