1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from number_theory import frobenius_solve from collections import defaultdict # squares up to 225 sq_set = {n * n for n in range(16)} # denominations for pre-decimal era coins dn = '1/2d 1d 3d 6d 1s 2s 2s6d'.split() # coin values in half penny units coins = (1, 2, 6, 12, 24, 48, 60) # for solutions indexed on the number of different numbers of each coin n2c = defaultdict(list) # find combinations of coins that add up to 10 shillings for s in frobenius_solve(coins, 240): # the must be at least one of all denominations if min(s) > 0: # all numbers of coins must be square if all(n in sq_set for n in s): n2c[len(set(s))].append(s) # find a solution that is unique for the number of # different numbers of coins for k, ls in n2c.items(): if len(ls) == 1: print(', '.join(str(n) + ' x ' + d for n, d in zip(ls[0], dn))) |