Solving two brainteasers 舅母 gave me

Sun May 09 2021

tags: fun public

Introduction

I was given these problems by my 舅母:

/img/aaren_brainteasers/question.jpg

The questions are actually quite poorly written (in the sense that they are ambiguous) but the ambiguity actually makes them inadvertently more challenging and thus more interesting.

Swimmers and non-swimmers

The native inhabitants of a certain island country have a strange characteristic: those who are swimmers always tell the truth. But those who are nonswimmers always lie. Suppose that you visit the island and meet a group of three people who are native inhabitants. You ask the first person, "Are you a swimmer?" The answer is unintelligible. The second person immediately says, "That was 'Yes.' I am a swimmer, too." The third person says, "They are both lying." Is each of these three people a swimmer or a nonswimmer?

Answer: It depends on how you interpret "nonswimmers always lie". Possible answers: SSN, NNS, SNN.

Firstly, let's note that even though the answer of the first person is unintelligible, it must always be "yes". This is because a swimmer will always honestly answer "Yes" and a nonswimmer will always lie and say "Yes" too.

The answer to this question depends completely on how you interpret the phrase "nonswimmers must always lie"! Depending on your interpretation, possible solutions to this problem are two swimmers and a nonswimmer (SSN), NNS, and even SNN.

Suppose I always lie. Could I have said the statement "My name is Zheng Hong. I am eight feet tall."? That depends on how you interpret "always lie". Does it mean that every sentence in the utterance must be false? If so, I could not have said that, since "My name is Zheng Hong" is true. But if you take the utterance as a whole, then I could have said that, since the utterance as a whole is a lie.

In the same way, the sentence is "That was 'Yes'. I am a swimmer, too.". If "must always lie" means "every sentence must be a lie", then a nonswimmer could not possibly have said that, because "That was 'Yes'" is true. Hence the second person must have been a swimmer. But if we consider two sentences as one combined utterance, then the nonswimmer could have said that, since the combined utterance is false, and this would still follow the rule of "nonswimmers always lie". Then the second person could be a nonswimmer.

Let's consider the first situation where the second person must have been a swimmer. Then the first person must have been a swimmer. This is because if the first person was a nonswimmer, then the second person would not have said "I am a swimmer, too". The word "too" implies that the first person was a swimmer, but this would be a false statement if the first person was a nonswimmer. Hence the first person must have been a swimmer. But if both first and second are swimmers, then the last person must be a nonswimmer, because "They are both lying" must be a lie, since neither of them are lying. Hence, SSN.

Now let's consider the situation where the second person is a nonswimmer (?N?). In which case, the first person could have been a swimmer or nonswimmer. Let's consider swimmer first. SN?. Is the third person a swimmer or a nonswimmer? Let's review:

  1. "Yes" (true)
  2. "That was 'Yes'. I am a swimmer, too" (false)
  3. "They are both lying".

Sentence 3 must be a lie, since only one of them is lying. Hence, the third person is a nonswimmer. Thus, SNN.

We can also consider the case where the first person is a nonswimmer:

  1. "Yes" (false)
  2. "That was 'Yes'. I am a swimmer, too" (false)
  3. "They are both lying".

Here Sentence 3 must be the truth, since both of them are lying. Hence, the third person is a swimmer. Thus, NNS.

In fact, we can run through all 8 possible combinations of swimmers and non-swimmers:

  • SSS: impossible, since the third person would not say that they are both lying.
  • NSS: impossible, since the second person would not say that he "too" was a swimmer
  • SNS: impossible, since the third person would say that only the second person is lying
  • SSN: possible
  • NNS: possible
  • NSN: impossible, since the second person would not say that he "too" was a swimmer
  • SNN: possible
  • NNN: impossible, since the sentence "They are both lying" would be true if so.

Custom Dice

What whole numbers should appear on the twelve faces of two number cubes so that the probabilities that the top two faces show any sum from 1 to 12 inclusive are exactly the same?

Answer: There are infinitely many whole number solutions.

First of all, let's note that we can fill all the faces with '0', or '13', '14', etc. Then the probability that the top two faces show any sum from 1 to 12 will be 0, which is exactly the same. So this is technically a solution. But of course this is a trivial solution. We should look for non-zero probabilities.

So the idea is as follows. Consider a "counter" that counts the number of ways each number can be rolled. As an example, the counter for two regular 6-sided dice would look like this:

{
    2: 1,
    3: 2,
    4: 4,
    5: 4,
    6: 5,
    7: 6,
    8: 5,
    9: 4,
    10: 4,
    11: 2,
    12: 1,
}

For example, there are six ways to roll a 7: (1,6), (6,1), (2,5), (5,2), (3,4), (4,3), and that's why we have the row 7: 6.

For this question, we want a counter that looks like this:

{ 0: whatever, we don't care 1: X 2: X 3: X ... 11: X 12: X 13: whatever, we don't care 14: whatever, we don't care ... ... 25: whatever, we don't care }

where all the X's are the same (and ideally not 0).

You can actually solve this problem by thinking about it, and filling the dice from the smallest number onwards. First you know that you need a 0, because you can only roll a sum of 1 if you roll a 0 and a 1. And given that there are only 36 (6x6) possible outcomes of the dice, you should figure that there can only be 1, 2, or 3 occurrences of 1--12. I guessed 2, and indeed I did it by hand. But in fact, there are infinitely many solutions! Here is some code to find solutions:

import itertools, collections

def is_equal_probability(c: collections.Counter, start: int, end: int):
"""
Check if all numbers from start to end (inclusive)
have the same number of occurrences.
"""

occurrences = c[start]
for i in range(start, end+1):
if c[i] != occurrences:
return False
return True

# Generate 6-sided dice with the faces 0 to 12
# 13 choose 6: 1716 unique combinations
for dice1 in itertools.combinations(range(0, 13), 6):
for dice2 in itertools.combinations(range(0, 13), 6):
# Get all the 36 dice rolls
combinations = list(itertools.product(dice1, dice2))
assert(len(combinations) == 36)
# Once we have the 36 dice rolls,
# sum them up and count the number of each occurrence
c = collections.Counter([sum(_) for _ in combinations])
if c[1] > 0 and is_equal_probability(c, 1, 12):
print("Found a pair of dice that have equal probability of summing to a value from 1 to 12!")
print(f"Dice 1: {dice1}")
print(f"Dice 2: {dice2}")
print(f"The 36 possible combinations: {combinations}")
print(f"And their respective sums: {sorted(c.items())}")

And here's the output:

(base) lieu@DESKTOP-NV19JNO:~/dev/lieuzhenghong.com/root$ python3 dice.py 
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 2, 3, 4, 10)
Dice 2: (0, 1, 5, 6, 11, 12)
The 36 possible combinations: [(0, 0), (0, 1), (0, 5), (0, 6), (0, 11), (0, 12), (1, 0), (1, 1), (1, 5), (1, 6), (1, 11), (1, 12), (2, 0), (2, 1), (2, 5), (2, 6), (2, 11), (2, 12), (3, 0), (3, 1), (3, 5), (3, 6), (3, 11), (3, 12), (4, 0), (4, 1), (4, 5), (4, 6), (4, 11), (4, 12), (10, 0), (10, 1), (10, 5), (10, 6), (10, 11), (10, 12)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 3), (16, 2), (21, 1), (22, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 2, 3, 9, 11)
Dice 2: (0, 1, 4, 5, 8, 12)
The 36 possible combinations: [(0, 0), (0, 1), (0, 4), (0, 5), (0, 8), (0, 12), (1, 0), (1, 1), (1, 4), (1, 5), (1, 8), (1, 12), (2, 0), (2, 1), (2, 4), (2, 5), (2, 8), (2, 12), (3, 0), (3, 1), (3, 4), (3, 5), (3, 8), (3, 12), (9, 0), (9, 1), (9, 4), (9, 5), (9, 8), (9, 12), (11, 0), (11, 1), (11, 4), (11, 5), (11, 8), (11, 12)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 2), (16, 1), (17, 1), (19, 1), (21, 1), (23, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 2, 3, 9, 12)
Dice 2: (0, 1, 4, 5, 8, 11)
The 36 possible combinations: [(0, 0), (0, 1), (0, 4), (0, 5), (0, 8), (0, 11), (1, 0), (1, 1), (1, 4), (1, 5), (1, 8), (1, 11), (2, 0), (2, 1), (2, 4), (2, 5), (2, 8), (2, 11), (3, 0), (3, 1), (3, 4), (3, 5), (3, 8), (3, 11), (9, 0), (9, 1), (9, 4), (9, 5), (9, 8), (9, 11), (12, 0), (12, 1), (12, 4), (12, 5), (12, 8), (12, 11)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 3), (14, 2), (16, 1), (17, 2), (20, 2), (23, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 2, 9, 10, 11)
Dice 2: (0, 1, 3, 4, 6, 7)
The 36 possible combinations: [(0, 0), (0, 1), (0, 3), (0, 4), (0, 6), (0, 7), (1, 0), (1, 1), (1, 3), (1, 4), (1, 6), (1, 7), (2, 0), (2, 1), (2, 3), (2, 4), (2, 6), (2, 7), (9, 0), (9, 1), (9, 3), (9, 4), (9, 6), (9, 7), (10, 0), (10, 1), (10, 3), (10, 4), (10, 6), (10, 7), (11, 0), (11, 1), (11, 3), (11, 4), (11, 6), (11, 7)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 2), (16, 2), (17, 2), (18, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 3, 4, 6, 7)
Dice 2: (0, 1, 2, 9, 10, 11)
The 36 possible combinations: [(0, 0), (0, 1), (0, 2), (0, 9), (0, 10), (0, 11), (1, 0), (1, 1), (1, 2), (1, 9), (1, 10), (1, 11), (3, 0), (3, 1), (3, 2), (3, 9), (3, 10), (3, 11), (4, 0), (4, 1), (4, 2), (4, 9), (4, 10), (4, 11), (6, 0), (6, 1), (6, 2), (6, 9), (6, 10), (6, 11), (7, 0), (7, 1), (7, 2), (7, 9), (7, 10), (7, 11)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 2), (16, 2), (17, 2), (18, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 4, 5, 8, 11)
Dice 2: (0, 1, 2, 3, 9, 12)
The 36 possible combinations: [(0, 0), (0, 1), (0, 2), (0, 3), (0, 9), (0, 12), (1, 0), (1, 1), (1, 2), (1, 3), (1, 9), (1, 12), (4, 0), (4, 1), (4, 2), (4, 3), (4, 9), (4, 12), (5, 0), (5, 1), (5, 2), (5, 3), (5, 9), (5, 12), (8, 0), (8, 1), (8, 2), (8, 3), (8, 9), (8, 12), (11, 0), (11, 1), (11, 2), (11, 3), (11, 9), (11, 12)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 3), (14, 2), (16, 1), (17, 2), (20, 2), (23, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 4, 5, 8, 12)
Dice 2: (0, 1, 2, 3, 9, 11)
The 36 possible combinations: [(0, 0), (0, 1), (0, 2), (0, 3), (0, 9), (0, 11), (1, 0), (1, 1), (1, 2), (1, 3), (1, 9), (1, 11), (4, 0), (4, 1), (4, 2), (4, 3), (4, 9), (4, 11), (5, 0), (5, 1), (5, 2), (5, 3), (5, 9), (5, 11), (8, 0), (8, 1), (8, 2), (8, 3), (8, 9), (8, 11), (12, 0), (12, 1), (12, 2), (12, 3), (12, 9), (12, 11)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 2), (16, 1), (17, 1), (19, 1), (21, 1), (23, 1)]
Found a pair of dice that have equal probability of summing to a value from 1 to 12!
Dice 1: (0, 1, 5, 6, 11, 12)
Dice 2: (0, 1, 2, 3, 4, 10)
The 36 possible combinations: [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 10), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 10), (5, 0), (5, 1), (5, 2), (5, 3), (5, 4), (5, 10), (6, 0), (6, 1), (6, 2), (6, 3), (6, 4), (6, 10), (11, 0), (11, 1), (11, 2), (11, 3), (11, 4), (11, 10), (12, 0), (12, 1), (12, 2), (12, 3), (12, 4), (12, 10)]
And their respective sums: [(0, 1), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), (11, 2), (12, 2), (13, 2), (14, 2), (15, 3), (16, 2), (21, 1), (22, 1)]
"""

We can see that there are actually five unique solutions if you restrict your pips from 1 to 12:

Dice 1: (0, 1, 2, 3, 4, 10)
Dice 2: (0, 1, 5, 6, 11, 12)

Dice 1: (0, 1, 2, 3, 9, 11)
Dice 2: (0, 1, 4, 5, 8, 12)

Dice 1: (0, 1, 2, 3, 9, 12)
Dice 2: (0, 1, 4, 5, 8, 11)

Dice 1: (0, 1, 2, 9, 10, 11)
Dice 2: (0, 1, 3, 4, 6, 7)

Dice 1: (0, 1, 3, 4, 6, 7)
Dice 2: (0, 1, 2, 9, 10, 11)

But in fact there are lots more solutions (infinitely many, actually!) if you do not restrict the numbers you use in each face of the die from 1 to 12. For example, this is a possible solution:

Found a pair of dice that have equal probability of summing to any value from 1 to 12!
Dice 1: (1, 2, 3, 10, 11, 14)
Dice 2: (0, 3, 6, 11, 13, 14)
The 36 possible combinations: [(1, 0), (1, 3), (1, 6), (1, 11), (1, 13), (1, 14), (2, 0), (2, 3), (2, 6), (2, 11), (2, 13), (2, 14), (3, 0), (3, 3), (3, 6), (3, 11), (3, 13), (3, 14), (10, 0), (10, 3), (10, 6), (10, 11), (10, 13), (10, 14), (11, 0), (11, 3), (11, 6), (11, 11), (11, 13), (11, 14), (14, 0), (14, 3), (14, 6), (14, 11), (14, 13), (14, 14)]
And their respective sums: [(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1), (12, 1), (13, 2), (14, 4), (15, 2), (16, 3), (17, 3), (20, 1), (21, 1), (22, 1), (23, 1), (24, 2), (25, 2), (27, 1), (28, 1)]

You can of course replace the numbers 13 and 14 by any other whole numbers that are larger, which would not change the result.