Brain-Teaser 685: Overseas mail
From The Sunday Times, 1st September 1974 [link]
We were visiting the island state of Kimbu and had come to the post-office to send off some parcels to friends at home. The island’s currency is the pim, and the postmaster told us that he had only stamps of five different face-values, as these had to be used up before a new issue of stamps was introduced.
These stamps were black, red, green, violet, and yellow, in descending order of values, the black being the highest denomination and the yellow the lowest.
One parcel required stamps to the value of 100 pims and we were handed 9 stamps; 5 black, one green, and 3 violet. The other two parcels required 50 pims’ worth each, and for these we were given two different sets of 9 stamps.
One consisted of 1 black and 2 of each of the other colours, and the other set contained 5 green and 1 of each of the others.
What would be been the smallest number of stamps needed for a 50-pim parcel, and of which colours?
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.
[teaser685]
Jim Randell 9:20 am on 28 January 2021 Permalink |
I assumed the denominations of the stamps were all positive integer values.
We can place lower and upper limits on the values of the stamps.
The stamps are ordered: B > R > G > V > Y, which gives minimum values of: 5, 4, 3, 2, 1.
And 5 black stamps are used in making a value of 100, so black must have a value of less than (100 − (3 + 3×2)) / 5 = 18.2.
Similarly, 5 green stamps are used in making a value of 50, so green must have a value of less than (50 − (5 + 4 + 2 + 1)) / 5 = 7.6.
So we can write down the following ranges for each denomination:
And we have three equations relating the values. So choosing values for V and Y will give us a set of 5 simultaneous equations that can be solved to find the other values.
This Python program use the [[
matrix.linear()]] solver for systems of linear equations from the enigma.py library. It runs in 63ms.Run: [ @repl.it ]
from enigma import (irange, subsets, matrix, as_int, express, group, printf) # choose values for Y and V for (Y, V) in subsets(irange(1, 6), size=2): # make the equations eqs = [ # B R G V Y = ??? ((5, 0, 1, 3, 0), 100), # 100-pim parcel ((1, 2, 2, 2, 2), 50), # 1st 50-pim parcel ((1, 1, 5, 1, 1), 50), # 2nd 50-pim parcel ((0, 0, 0, 0, 1), Y), # Y value ((0, 0, 0, 1, 0), V), # V value ] # solve the equations for integer values # (either matrix.linear() or as_int() may raise a ValueError) try: (B, R, G, V, Y) = (as_int(x) for x in matrix.linear(*zip(*eqs))) except ValueError: continue # check ordering if not (B > R > G > V > Y > 0): continue # find combinations that make 50, grouped by the total number of stamps d = group(express(50, [Y, V, G, R, B]), by=sum) # output minimal configurations k = min(d.keys()) for (y, v, g, r, b) in d[k]: printf("{k} stamps; 50 = {b}x {B} (black), {r}x {R} (red), {g}x {G} (green), {v}x {V} (violet), {y}x {Y} (yellow)")Solution: A 50-pim parcel can be sent using 5 stamps: 2 black, 1 red, 1 green, 1 yellow.
The values of the stamps are:
So each stamp is half (rounded down) the next highest value.
There are 621 different ways to make 50 using the above denominations.
Here’s a manual derivation of the denominations:
Taking 2×[2] − [1] gives:
And we know G is in the range 3 .. 7, and B is in the range 5 .. 18 and G < B:
And:
Where V is in the range 2 .. 6 and V < G:
So we have: V = 2, G = 4, B = 18.
From which we see Y = 1, and R = 9.
LikeLike
Jim Randell 5:55 pm on 28 January 2021 Permalink |
Here’s a solution using the [[
SubstitutedExpression]] solver from the enigma.py library. It runs in 122ms.It operates in base 19 as B ≤ 18.
The only other restriction I used was that we already know that 50 is possible with 9 stamps, so I limit the numbers used for any single denomination to 8. (We can also do this in my Python program above, by passing [[
qs=irange(0, 8)]] to the call to [[express()]] and that saves a little bit of time).We could restrict the other denominations in line with the ranges given above, but it is not necessary for a decent run time.
Run: [ @repl.it ]
LikeLike
Frits 12:24 pm on 28 January 2021 Permalink |
from enigma import SubstitutedExpression # the alphametic puzzle p = SubstitutedExpression( [ # try to avoid looping over BL and RE "G > V", "V > Y", # (5, 0, 1, 3, 0) 100-pim parcel "(100 - G - 3*V) // 5 = BL", # (1, 2, 2, 2, 2) 1st 50-pim parcel "(50 - BL) // 2 - (G + V + Y) = RE", "RE > G", "BL > RE", # (1, 1, 5, 1, 1) 2nd 50-pim parcel "BL + RE + 5*G + V + Y = 50", # Pick M blacks, N reds, O greens, P violets and Q yellows # we already know a 50-pim parcel can be formed with 9 stamps "M + N < 10", "M + N + O < 10", "M + N + O + P < 10", "M + N + O + P + Q < 10", "M*BL + N*RE + O*G + P*V + Q*Y = 50", ], answer="M + N + O + P + Q, M, N, O, P, Q", distinct="", accumulate=min, # BL: 5..18 RE: 4..12 G: 3..7 V: 2..6 Y: 1..5 d2i=dict([(0, "GVY")] + [(1, "VG")] + [(2, "RBG")] + [(k, "RB") for k in range(3, 6)] + [(6, "YRB")] + [(7, "YVRB")] + [(k, "YVGRBMNOPQ") for k in range(8, 10)]), reorder=0, verbose=0 ) # solve the puzzle r = p.run() colors = ["black", "red", "green", "violet", "yellow"] for (x, y) in zip(list(r.accumulate)[1:], colors): if x > 0: print(x, y)LikeLike
GeoffR 3:04 pm on 28 January 2021 Permalink |
LikeLike
John Crabtree 12:07 am on 29 January 2021 Permalink |
Eq. 1: 5.B + 0.R + 1.G +3.V + 0.Y = 100
Eq. 2: 1.B + 2.R + 2.G +2.V + 2.Y = 50
Eq. 3 : 1.B + 1.R + 5.G +1.V + 1.Y = 50
10 * Eq. 3 – 5 * Eq. 2 – Eq. 1 gives 39.G – 3.V = 150, or 13.G – V = 50
Assuming integer solutions, G = 4, V = 2 and then B = 18, R + Y = 10 etc
LikeLike