Teaser 2581: Resplendency
From The Sunday Times, 11th March 2012 [link] [link]
Our local Hibernian band will lead the St Patrick’s Day parade next Saturday, resplendent in their new tunics and finery. The total cost of this was one thousand pounds and it was generously paid for by the parish council. Each tunic cost the same two-figure number of pounds (and that number happens to be double the number of girls in the band). In addition, each girl in the band has some extra finery, and the cost of this for each girl was the same as the cost of the tunic but with the two digits in reverse order.
How many boys and how many girls are there in the band?
[teaser2581]
Jim Randell 10:40 am on 31 January 2025 Permalink |
If:
we have:
Hence b, g, f can all be expressed in terms of t, which is a 2-digit even number.
This Python program runs in 66ms. (Internal runtime is 57µs).
from enigma import (irange, cproduct, div, printf) # the cost of each tunic is XY, a 2-digit even number # the cost of each finery is YX, a 2 digit number for (X, Y) in cproduct([irange(1, 9), [2, 4, 6, 8]]): (t, f) = (10 * X + Y, 10 * Y + X) # calculate the number of girls and boys g = t // 2 b = div(1000 - (t + f) * g, t) if b is None or b < 0: continue # output solution printf("b={b} g={g}; t={t} f={f}")Solution: There are 24 boys and 8 girls.
The tunics cost £ 16, and the finery costs £ 61.
LikeLike
Ruud 3:58 pm on 2 February 2025 Permalink |
Very straightforward:
import peek import istr for n_girls in istr(range(5, 50)): tunic_cost = 2 * n_girls finery_cost = tunic_cost.reversed() girls_total = n_girls * (tunic_cost + finery_cost) boys_total = 1000 - girls_total if finery_cost[0] != 0 and boys_total.is_divisible_by(tunic_cost): n_boys = boys_total / tunic_cost peek(girls_total, boys_total, n_girls, n_boys, tunic_cost, finery_cost)LikeLike
GeoffR 9:03 am on 1 February 2025 Permalink |
# the cost of each tunic is XY, a 2-digit even number # the cost of each finery is YX, a 2 digit number for X in range(1, 9): for Y in range(2, 10, 2): XY, YX = 10*X + Y, 10*Y + X for girls in range(1, 100): # cost of a tunic is double the number of girls if XY != 2 * girls:continue for boys in range(1, 100): tunics = (boys + girls) * XY finery = girls * YX # total cost = £1,000 if tunics + finery == 1000: print(f"Band = {boys} boys and {girls} girls.") # Band = 24 boys and 8 girls.LikeLike