Tagged: by: Arthur Adams Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 9:09 am on 18 November 2021 Permalink | Reply
    Tags: by: Arthur Adams   

    Brain-Teaser 884: Mice in the works 

    From The Sunday Times, 16th July 1978 [link]

    Recently a hot-drink vending machine was installed in our office. Very nice it is too — completely up to date it was when it was bought. There are five switches, a slot for your money, and a button. The switches are labelled TEA, COFFEE, CHOCOLATE, MILK and SUGAR, and you select the combination you want, put in your money, press the button, and out comes your drink. Why, you can even have coffolatea if you want!

    At least, this is the idea. Unfortunately, during the ten years it has been in store, “awaiting approval”, mice have chewed up the wiring. Mice with soldering irons, I should think. The result is now that no switch affects its “own” ingredient at all, but instead turns on two other ingredients, each ingredient being turned on by two different switches. However, if two switches are set which turn on the same ingredient, then they cancel each other out, and that ingredient doesn’t come out at all.

    The result is somewhat chaotic, though occasionally some of the output is actually drinkable. For instance, when you ask for white sweet coffee, you get unsweetened milky tea; when you ask for sweet milky chocolate, you get sweet chocolate without milk; and when you ask for unsweetened milky tea you get a glorious gooey mocha — i.e. chocolate and coffee with milk and sugar.

    Luckily, pressing the “deliver” button reinstates the original chaos, so that setting the same switches always gives the same results.

    So, what is the easiest way to get white coffee without sugar? (i.e. Name the fewest switches that will deliver just coffee and milk).

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.

    [teaser884]

     
    • Jim Randell's avatar

      Jim Randell 9:12 am on 18 November 2021 Permalink | Reply

      We’ve seen puzzles like this before. See Enigma 91, Puzzle #103 (although this puzzle was published before either of them).

      I reused the code I wrote for Puzzle #103.

      The following Python 3 program runs in 60ms.

      Run: [ @replit ]

      from enigma import (multiset, subsets, diff, update, ordered, join, map2str, printf)
      
      # buttons
      buttons = 'T Cf Ch M S'.split()
      
      # map each value in <ks> to <n> other values chosen from mutliset <vs>
      # return map d: <ks> -> <n>-tuples from <vs>
      def make_map(ks, vs, n=2, d=dict()):
        # are we done?
        if not ks:
          yield d
        else:
          # choose n values for the next key
          k = ks[0]
          for ss in subsets(diff(vs.keys(), [k]), size=n):
            yield from make_map(ks[1:], vs.difference(ss), n, update(d, [(k, ordered(*ss))]))
      
      # outcome of selecting buttons <bs> using map <d>
      def select(d, bs):
        m = multiset()
        for b in bs:
          m.update_from_seq(d[b])
        return set(k for (k, v) in m.items() if v == 1)
      
      # consider possible maps
      for d in make_map(buttons, multiset.from_seq(buttons, count=2)):
      
        # select M+S+Cf -> M+T
        if not (select(d, ['M', 'S', 'Cf']) == {'M', 'T'}): continue
      
        # select S+M+Ch -> S+Ch
        if not (select(d, ['S', 'M', 'Ch']) == {'S', 'Ch'}): continue
      
        # select M+T -> Ch+Cf+M+S
        if not (select(d, ['M', 'T']) == {'Ch', 'Cf', 'M', 'S'}): continue
      
        # answer, easiest way to get Cf+M?
        for bs in subsets(buttons, min_size=1):
          if select(d, bs) == {'Cf', 'M'}:
            fmt = lambda s: join(sorted(s), sep="+")
            printf("{bs} -> Cf+M {d}", bs=fmt(bs), d=map2str(((k, fmt(v)) for (k, v) in d.items()), arr="->", enc="[]"))
      

      Solution: The easiest way to get coffee and milk is to select “Coffee” and “Milk”.

      There is also a combination of 3 buttons that will give coffee and milk: “Chocolate”, “Tea” and “Sugar”.

      The items delivered by the buttons are:

      Coffee: Chocolate + Milk
      Chocolate: Tea + Sugar
      Milk: Coffee + Chocolate
      Sugar: Coffee + Tea
      Tea: Milk + Sugar

      Like

    • John Crabtree's avatar

      John Crabtree 5:44 pm on 25 November 2021 Permalink | Reply

      Using the same switch twice selects nothing. Using all five switches selects nothing. Call this statement S4
      Using all of the switches in statements S1, S2, S3 and S4 results in: using S gives Cf and T
      S1 reduces to: using Cf and M gives Cf and M
      This is one possible answer, but we do not know that it is the shortest.
      From S1 and S, using M gives Cf
      From S2 and S, using M gives Ch as well as Cf (from above)
      From S1, using Cf gives Ch and M
      From S2, using Ch gives S and T
      From S3, using T gives M and S

      Since no one button gives Coffee with Milk, pressing Coffee and Milk is the simplest way to get Coffee with Milk

      This solution is much simpler that the official one in the book.

      Like

  • Unknown's avatar

    Jim Randell 9:55 am on 29 June 2021 Permalink | Reply
    Tags: by: Arthur Adams   

    Brain-Teaser 790: Multi-value coil 

    From The Sunday Times, 5th September 1976 [link]

    Post Office multi-value coil machines are designed to vend strips of five stamps. Soon after the introduction of the 8½p and 6½p first and second class postal rates the machines sold for 10p a strip of stamps values 6p, 1p, ½p, 2p and ½p respectively (as always with these machines the last stamp being the lowest in case of tearing). While catering for both rates it was impossible to make up either 6½p or 8½p with a joined strip of stamps.

    However an efficiency expert worked out a possible 10p strip which afforded the following:

    (i) from one strip either first or second rate in a joined strip;
    (ii) from two joined strips, three second class rates, each in a joined strip;
    (iii) from three joined strips, two first class rates plus two second class rates,  each in a joined strip.

    Of course the “expert” assumed that all ½p steps from ½p to 10p were available in stamps.

    What was his suggested strip?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.

    [teaser790]

     
    • Jim Randell's avatar

      Jim Randell 9:56 am on 29 June 2021 Permalink | Reply

      Working in units of half-pennies we can keep amounts in integers.

      The value of one complete strip is 20 (= 10p), the first class rate is 17 (= 8.5p), and the second class rate is 13 (= 6.5p).

      This Python 3 program runs in 82ms.

      Run: [ @replit ]

      from enigma import irange, subsets, printf
      
      # decompose total <t> into <k> positive integers
      def decompose(t, k, ns=[]):
        if k == 1:
          yield ns + [t]
        else:
          k -= 1
          for n in irange(1, t - k):
            yield from decompose(t - n, k, ns + [n])
      
      # can values in <vs> be made from segments of <ss>
      def _connected(vs, ss):
        # are we done?
        if not vs:
          return True
        else:
          v = vs[0]
          ss = list(x for x in ss if x)  # drop empty lists
          # consider segments
          for (i, ns) in enumerate(ss):
            if sum(ns) < v: continue  # shortcut
            # and sub-segments
            for (j, k) in subsets(irange(0, len(ns)), size=2):
              if sum(ns[j:k]) == v:
                if _connected(vs[1:], ss[:i] + ss[i + 1:] + [ns[:j], ns[k:]]):
                  return True
          return False
      
      connected = lambda vs, ns: _connected(vs, [ns])
      
      # check a sequence
      def check(ns):
        # (i) 13 and 17 can be made from 1 strip
        if not(connected([13], ns) and connected([17], ns)): return False
        # (ii) three lots of 13 from 2 joined strips
        if not(connected([13] * 3, ns * 2)): return False
        # (iii) two lots of 13 _and_ two lots of 17 from 3 joined strips
        if not(connected([13, 17] * 2, ns * 3)): return False
        # passed
        return True
      
      # look for viable strips
      for ns in decompose(20, 5):
        # lowest value stamp comes last
        if ns[-1] == min(ns) and check(ns):
          # output solution
          printf("strip = {ns}")
      

      Solution: The stamps on the suggested strip were: 1½p, 1½p, 3½p, 3p, ½p.

      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