Tagged: by: J L Powell Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 8:26 am on 15 October 2019 Permalink | Reply
    Tags: by: J L Powell   

    Brain-Teaser 505: [Colourland] 

    From The Sunday Times, 14th February 1971 [link]

    Colourland is inhabited by three races, all similar in appearance — Redmen, a truthful people; Greenmen, who always lie; and Bluemen, who sometimes tell the truth and sometimes lie. Their houses are painted either red, green or blue, but no one lives in a house with the colour of his race name.

    One day, after a football match, three of the winning team, which won 1-0, were standing together. Their shirts were numbered 1, 2 and 3, and by tradition these three would be one from each race, each occupying a different coloured house.

    I asked number 1 if number 2 told the truth more often than number 3, to which he answered “No”. I then asked number 2 if any of the three of them had scored the winning goal, his reply being “I did”.

    I next asked one of them if he lived in a certain coloured house, and from his reply I was in fact able to determine:

    (i) the colour of each tribesman’s house, and:
    (ii) which (if any) scored the goal.

    Can you?

    This puzzle was originally published with no title.

    [teaser505]

     
    • Jim Randell's avatar

      Jim Randell 8:27 am on 15 October 2019 Permalink | Reply

      The tribes on the island are described as “similar in appearance”, which I take to mean that the setter is not able to determine which tribe the person he is questioning is from, other than from the answers to the questions.

      This Python program runs in 84ms.

      from enigma import (subsets, cproduct, join, printf)
      
      # honesty rating
      h = dict(R=2, B=1, G=0)
      
      # valid replies for tribe t, statement s
      def valid(t, s):
        s = bool(s)
        if t == "R": return s
        if t == "G": return (not s)
        return True
      
      # collect responses
      rs = list()
      
      # assign tribes
      for (t1, t2, t3) in subsets("RGB", size=len, select="P"):
      
        # check statement: "Is 2 more truthful than 3?" -> 1: "No"
        if not valid(t1, not (h[t2] > h[t3])): continue
      
        # choose a goal scorer
        for g in (0, 2):
      
          # check statement: "Who scored the winning goal?" -> 2: "2"
          if not valid(t2, g == 2): continue
      
          # assign houses
          for (h1, h2, h3) in subsets("RGB", size=len, select="P"):
            # no one lives in the same colour house as his tribe
            if t1 == h1 or t2 == h2 or t3 == h3: continue
      
            rs.append(((t1, t2, t3), (h1, h2, h3), g))
      
      
      # Q3 to player P: "Is the colour of your house Q?"
      for (P, Q) in cproduct([(1, 2, 3), "RGB"]):
        i = P - 1 # index for player P
      
        # collect results
        (ys, ns) = (set(), set())
        for (tribes, houses, g) in rs:
      
          # solution is (house colours by tribe, goal scorer)
          s = (tuple(x + houses[tribes.index(x)] for x in "RGB"), ("2" if g == 2 else "not 2"))
      
          # answer is "Yes"
          if valid(tribes[i], houses[i] == Q):
            ys.add(s)
      
          # answer is "No"
          if valid(tribes[i], houses[i] != Q):
            ns.add(s)
      
        # examine the responses
        for (s, t) in zip([ys, ns], ["Yes", "No"]):
          # we only want one
          if len(s) != 1: continue
          (hs, g) = s.pop()
          # and the goal scorer must be determined
          if g.startswith("not "): continue
          # output solution
          printf("Q3 to player {P}: \"Is your house {Q}?\"; {t} -> houses = {hs}; scorer = {g}", hs=join(hs, sep=" "))
      

      Solution: Yes. (i) Redman in blue house. Blueman in green house. Greenman in red house; (ii) Redman scored the goal.

      The third question is asked of player 2, and is: “Is your house green?”.

      An answer of “No” allows the questioner to infer:

      Player 2 is Redman. His house is blue. He scored the goal.
      Player 1 and 3 are: Greenman in a red house and Blueman in a green house, but we don’t know which player has which number.

      Similarly, if the third question asked (still of player 2) is: “Is your house red?”, and the answer received is “Yes”, then we can infer:

      Player 2 is Greenman. His house is blue. He did not score the goal.
      Player 1 and 3 are: Redman in a green house and Blueman in a red house, but we don’t which player has which number.

      But we cannot determine who the goal scorer is, only that it isn’t player 2.


      If we consider the first question.

      If the person we ask is Blue, then they could answer anything. So the following are possible:

      #1=B, #2=R, #3=G
      #1=B, #2=G, #3=R

      If the person asked the first question is Red, then #2 does not tell the truth more often than #3:

      #1=R, #2=G, #3=B

      If the person asked the first question is Green, then #2 does tell the truth more often than #3:

      #1=G, #2=R, #3=B

      So there are four possible assignments of players to tribes, and #2 is not Blue, so we can ask them a question, and know we are not going to get a “random” answer.

      If we ask #2 “Do you live in a green house?”. We know if G is asked this they must answer “Yes” (as they don’t), so if we get an answer of “No” we know that #2 must be R, and they do not live in a green house.

      In this situation the houses are: RB, BG, GR, and we also know that R is #2, and so answered Q2 truthfully, so R scored the goal.

      Like

  • Unknown's avatar

    Jim Randell 10:53 pm on 16 February 2019 Permalink | Reply
    Tags: by: J L Powell   

    Brain-Teaser 452: [Coloured dice] 

    From The Sunday Times, 11th January 1970 [link]

    Three dice, numbered from 1 to 6, each had 2 blue, 2 red and 2 white faces. No number appeared in the same colour twice.

    When  Bill threw the dice they totalled 14, showing 2 white faces and 1 red. A second throw showed each die the same colour as before, but each had a different number totalling 15. On one die Bill noticed two similarly coloured sides added to 9.

    The telephone rang and Bill went to answer it, leaving little Tommy by himself, who then picked up one of the dice and painted a red face white and a white face red. He then threw the dice twice producing firstly 3 whites and then 3 reds, each throw showing one of the repainted sides.

    Tommy totalled the 3 whites to 8 and the 3 reds to 7. Unfortunately, sums were not his strong point and though he sometimes got them right, quite often he was 1 out, and sometimes even 2 out. However, he was certain that the 3 whites totalled more than the 3 reds.

    What numbers did Tommy repaint (1) red, and (2) white?

    This puzzle was originally published with no title.

    [teaser452]

     
    • Jim Randell's avatar

      Jim Randell 10:55 pm on 16 February 2019 Permalink | Reply

      This Python program runs in 370ms.

      Run: [ @repl.it ]

      from collections import namedtuple
      from itertools import permutations, combinations, product
      from enigma import irange, partitions, printf
      
      # represent a die
      Die = namedtuple("Die", "B R W")
      
      # collect possible dice
      dice = set(Die(*s) for ns in partitions(irange(1, 6), 2) for s in permutations(ns))
      
      # can we make the numbers in <ns> from the opposite faces of <fs>
      def make(ns, fs):
        ns = set(ns)
        (f1, f2, f3) = fs
        return any(ns.issubset([f1[i1] + f2[i2] + f3[i3], f1[1 - i1] + f2[1 - i2] + f3[1 - i3]]) for (i1, i2, i3) in product((0, 1), repeat=3))
      
      # change tuple <t> so index <i> is <v>
      def change(t, i, v):
        t = list(t)
        t[i] = v
        return tuple(t)
      
      # possible white, red values for Tommy (white > red)
      ts = set((w, r) for w in irange(6, 10) for r in irange(5, w - 1))
      
      # choose a set of three dice
      for (d1, d2, d3) in combinations(dice, 3):
      
        # "no number appeared in the same colour twice"
        if not all(len(set(x1 + x2 + x3)) == 6 for (x1, x2, x3) in zip(d1, d2, d3)): continue
      
        # "on one of the dice two similary coloured sides add up to 9"
        if not any(sum(x) == 9 for x in d1 + d2 + d3): continue
      
        # can we make a R, W, W combination that sums to 14 and 15
        if not any(make((14, 15), fs) for fs in [(d1.R, d2.W, d3.W), (d1.W, d2.R, d3.W), (d1.W, d2.W, d3.R)]): continue
      
        # Tommy picked one of the dice and swapped the colours of a red number and a white number, suppose he repaints t1
        for (t1, t2, t3) in [(d1, d2, d3), (d2, d1, d3), (d3, d1, d2)]:
          # choose red/white faces of t1 to repaint
          for (r, w) in product((0, 1), repeat=2):
            # the repainted die
            t = Die(B=t1.B, R=change(t1.R, r, t1.W[w]), W=change(t1.W, w, t1.R[r]))
      
            # record possible 3 white/red scores (including the repainted faces)
            ws = set(sum(s) for s in product([t.W[w]], t2.W, t3.W))
            rs = set(sum(s) for s in product([t.R[r]], t2.R, t3.R))
      
            # do these create feasible values?
            vs = ts.intersection(product(ws, rs))
            if vs:
              printf("dice: {t1} {t2} {t3}")
              printf("  red = {r}, white = {w} -> {vs}", r=t.R[r], w=t.W[w])
      

      Solution: (1) Tommy repainted 3 to red, (2) and 4 to white.

      There is only one possible set of dice:

      die 1: blue = 1,5; red = 2,4; white = 3,6
      die 2: blue = 2,6; red = 1,3; white = 4,5
      die 3: blue = 3,4; red = 5,6; white = 1,2

      The throws for Bill, showing 2 white faces and 1 red:

      throw 1: die 1 = white 3; die 2 = white 5; die 3 = red 6; total = 14
      throw 2: die 1 = white 6; die 2 = white 4; die 3 = red 5; total = 15

      Both die 1 and die 2 have white faces that sum to 9.

      Tommy chooses die 1 and repaints 3 from white to red, and 4 from red to white, giving (with the repainted faces indicated in braces):

      die 1: blue = 1,5; red = 2,{3}; white = {4},6
      die 2: blue = 2,6; red = 1,3; white = 4,5
      die 3: blue = 3,4; red = 5,6; white = 1,2

      Tommy then throws 3 whites (totalling 6 to 10), and then 3 reds (totalling 5 to 9), the white total being more than the red total.

      throw 1: die 1 = {white 4}; die 2 = white 4; die 3 = white 2; total = 10
      throw 2: die 1 = {red 3}; die 2 = red 1; die 3 = red 5; total = 9

      So Tommy’s calculation of 8 for the reds and 7 for the whites were both out by 2.

      Like

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
Design a site like this with WordPress.com
Get started