Enigmatic Code

Programming Enigma Puzzles

Enigma 860: Weight for it!

From New Scientist #2015, 3rd February 1996 [link]

I used to run a village shop and I had a pair of scales and a set of 10 weights. Each weight was a whole number of ounces and the total weight was less than 1024 ounces. I found that I could [not] put one or more weights on each of the two pans of my scales so that they balanced.

One day I lost a weight. By chance I was able to replace it with a spare; unfortunately it was not the same weight as the one I lost. However, now I could put one or more weights on each of the two pans of my scales so that they balanced; in fact, I could arrange for each side to weigh 6 ounces. Unfortunately I could not weigh 13 ounces, although I could weigh 3 ounces.

Q1. What was my set of weights after the replacement?

Q2. Suppose I was back with my original set of weights. Could I have selected one and replaced it by some other whole-number-of-ounces weight, of my own choosing, so that the total weight was still less than 1024 ounces and I still could not put one or more weights on each of the two pans of my scales so that they balanced?

Q3. As Q2 but now I can replace six weights instead of just one. The new set of weights must not be the same as my original set.

This statement takes into account the correction to the puzzle published with Enigma 866.

I also added the “not” in square brackets into the text, as without it the puzzle doesn’t make sense to me.


One response to “Enigma 860: Weight for it!

  1. Jim Randell 13 June 2022 at 3:12 pm

    If there are 10 weights, then by combining them we can make (2^10 − 1) = 1023 non-empty collections of weights.

    And each of those collections must have a different value (total weight), in the range 1 – 1023 (otherwise we would be able to find two sets of weights that balanced).

    The only way to achieve this is to use weights that are powers of 2.

    So the initial set of weights is: (1, 2, 4, 8, 16, 32, 64, 128, 256, 512).

    And this answers the second and third questions:

    Solution: Q2, Q3: No.

    And so we turn to Q1:

    With the replacement we can’t make 13, so one of the lost weights must be (1, 4, 8) (as these are the unique set of weights used to make 13), and there is more than one way to make 6, so the replacement weight cannot weigh more than 6.

    This Python program runs in 60ms. (Internal run time is 376µs).

    Run: [ @replit ]

    from enigma import (irange, first, update, subsets, group, multiset, printf)
    # starting set of weights [1, 2, 4, ..., 512]
    ws0 = list(2 ** i for i in irange(0, 9))
    printf("[initial = {ws0}]")
    # Q1 we only need to consider weights up to 13
    ws1 = first(ws0, (lambda w: not(w > 13)))
    # try replacing one of the weight with another, up to 6
    for r in irange(1, 6):
      for (i, w) in enumerate(ws1):
        # replacement must be different, and used in making 13
        if w == r or 13 & w == 0: continue
        # make the replacement
        ws = update(ws1, [(i, r)])
        # find values that can be made with the new set
        d = group(subsets(ws, min_size=1), by=sum)
        # check the conditions: can make 3, cannot make 13, can make 6
        if not(3 in d and 13 not in d and 6 in d): continue
        # can make 6 in 2 ways
        ms = multiset.from_seq(ws)
        if not any(ms.issuperset(w1 + w2) for (w1, w2) in subsets(d[6], size=2)): continue
        # output solution
        ws.extend(w for w in ws0 if w > 13)
        printf("Q1: replace {w} with {r} -> {ws}")

    Q1: After replacement the set of weights had values: 1, 2, 4, 5, 16, 32, 64, 128, 256, 512.

    After the replacement we can’t make 13, 14, 15. But 6 can be made from 1+5 or 2+4 (and we could also balance 5 = 1+4).

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 )

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: