Enigmatic Code

Programming Enigma Puzzles

Puzzle #41: Hen party dorm

From New Scientist #3264, 11th January 2020 [link]

Ten friends have rented a dormitory for the night of a hen party. Each person picks a bed for the night before heading out on the town. At 2 am they start heading home a little the worse for wear.

Amy, the first to arrive back at the dorm, can’t remember which bed she chose, so she picks one at random. The next person to return, Bethan, heads for her own bed, but if she finds it has already been taken, she randomly picks another.

The remaining friends adopt the same approach of going to their bed if it is available and randomly picking another if it isn’t. Janice is the last to get home. What is the chance that her own bed is still empty? And was Janice more or less likely to find the bed she first chose empty than Iona, who got back just before her?


One response to “Puzzle #41: Hen party dorm

  1. Jim Randell 11 January 2020 at 10:02 am

    This Python 3 program generates all possible outcomes, along with their probabilities and then sums the probabilities where each girl occupies her original bed. It runs in 109ms.

    Run: [ @repl.it ]

    from fractions import Fraction as F
    from enigma import irange, printf
    # possible numbers
    ns = set(irange(1, 10))
    # generate outcomes and probabilities
    def allocate(k, ns, s=[], f=F(1, 1)):
      # are we done?
      if not ns:
        yield (s, f)
        # try your own number (except k = 1)
        if k > 1 and k in ns:
          yield from allocate(k + 1, ns.difference([k]), s + [k], f)
          # else choose a number at random
          t = len(ns)
          for n in ns:
            yield from allocate(k + 1, ns.difference([n]), s + [n], f / t)
    # sum the probabilities that each gets their original number
    p = dict((i, 0) for i in ns)
    for (s, f) in allocate(1, ns):
      for (i, x) in enumerate(s, start=1):
        if x == i: p[i] += f
    # output the probabilities
    for (i, x) in enumerate("ABCDEFGHIJ", start=1):
      printf("p({x}) = {p}", p=p[i])

    Solution: The chance that Janice finds her original bed unoccupied is 1/2. The chance that Iona finds her original bed unoccupied is 2/3, so it is less likely that Janice finds her original bed unoccupied.

    The probability that the described strategy results in each girl ending up in her original bed is:

    A = 1/10
    B = 9/10
    C = 8/9
    D = 7/8
    E = 6/7
    F = 5/6
    G = 4/5
    H = 3/4
    I = 2/3
    J = 1/2

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: