Enigmatic Code

Programming Enigma Puzzles

Tantalizer 439: High life

From New Scientist #990, 4th March 1976 [link]

The Enigma Quartet all live on different floors of a mammoth block of flats. Amble and the drummer are on adjacent floors. The harpist lives four floors above Bumble. Crumble and the flautist are ten floors apart.

None of the four lives on a floor served by a lift. For, although there are three lifts all serving floor 0, one stops only at every third floor, one only at every fourth and one only at every fifth. Apart from floor 0, no floor has three lifts stopping.

Since no musician will ever walk up stairs. Amble has no way of visiting the trombonists flat without walking down at least four sets of stairs. Which instrument does Dimwit play and which floor does he live on?

[tantalizer439]

One response to “Tantalizer 439: High life

  1. Jim Randell 12 December 2018 at 8:43 am

    I supposed that “floor 0” indicates the ground floor, and the remaining floors are numbered upwards sequentially from 1.

    The lowest common multiple of 3, 4, 5 is 60, so if there was a floor 60, all the lifts would stop there. So there must be fewer that 60 floors.

    This Python program chooses floors for Amble, Bumble and Crumble, and possible matching floors for the drummer, flautist, harpist and trombonist. The unmatched floor number must then belong to Dimwit. It runs in 81ms.

    Run: [ @repl.it ]

    from enigma import irange, is_distinct, diff, printf
    
    # minimum sets of stairs to walk down between floors from a to b
    def down(a, b):
      # go down to the first lift below a, and then down from the first lift above b
      x = min(a % 3, a % 4, a % 5) + min(-b % 3, -b % 4, -b % 5)
      # or just walk down
      y = a - b
      return (y if not(y < 0) and y < x else x)
    
    # "None of the four lives on a floor served by a lift"
    # so floors that are multiples of 3, 4, 5 are out
    Floor = set(n for n in irange(0, 59) if all(n % d != 0 for d in (3, 4, 5)))
    
    # choose a floor for Amble
    for A in Floor:
    
      # "Amble has no way of visiting the trombonists flat without walking down at least four sets of stairs"
      for t in Floor:
        if down(A, t) < 4: continue
    
        # "Amble and the drummer are on adjacent floors"
        for d in (A - 1, A + 1):
          if not(d in Floor and is_distinct(d, t)): continue
    
          # choose a floor for Bumble
          for B in Floor:
            if not is_distinct(A, B): continue
    
            # "The harpist lives four floors above Bumble"
            h = B + 4
            if not(h in Floor and is_distinct(h, t, d)): continue
            if not(len(set((A, B, t, d, h))) < 5): continue
    
            # choose a floor for Crumble
            for C in Floor:
              if not is_distinct(C, A, B): continue
    
              # "Crumble and the flautist are ten floors apart"
              for f in (C - 10, C + 10):
                if not(f in Floor and is_distinct(f, t, d, h)): continue
    
                # so D lives at whatever role based floor is unused
                D = diff((d, f, h, t), (A, B, C))
                if not(len(D) == 1): continue
                D = D[0]
    
                # output solution (highest to lowest)
                # f2r: Floor -> Role
                f2r = { d: "Drummer", f: "Flautist", h: "Harpist", t: "Trombonist" }
                for (k, n) in sorted(zip((A, B, C, D), ("Amble", "Bumble", "Crumble", "Dimwit")), reverse=True):
                  printf("{n}, {r}, floor {k}", r=f2r[k])
                printf()
    

    Solution: Dimwit plays the harp and lives on floor 26.

    The full solution is:

    Dimwit, Harpist, floor 26
    Amble, Flautist, floor 23
    Bumble, Drummer, floor 22
    Crumble, Trombonist, floor 13

    Amble can walk down 2 sets of stairs from floor 23 to floor 21, then take the 3-lift down to floor 15, and then walk down 2 more sets of stairs to reach the trombonist on floor 13.

    In fact there are no two floors that require Amble to walk down more than 4 sets of stairs, as you can never be more than two floors away from a lift. So, there are only 6 floors below 60 that Amble can live on: 2, 14, 23, 38, 47, 59.

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: