Brainteaser 1099: Jackpot!
From The Sunday Times, 28th August 1983 [link]
Our local maths club has an appropriate slot machine. It consists of the digits from 1 to 9 in a row and each of them has a star below it which can light up. The machine always has some of the stars lit up and the idea is to read the number formed by the lit-up digits. So, for example, in the situation illustrated the number is 14689.
There are four possible jackpots which this machine pays out. To have a go you observe the lit-up number, place 10p in the slot (which causes a different selection of digits to light), and observe the new number. (The machine is then ready for the next go). The jackpots are the “Fair Share” which is won if the number showing after putting in your 10p is precisely half the number which was showing before. The “Rare Square” which is won if the number showing after putting in your 10p is the square of the number showing before. The “Cute Root” which requires that the number before you place in the 10p is the square of the number showing afterwards. And the “Rum Sum” which is won if the number showing after you place in your 10p is the sum of the digit which were lit up before.
One member had a very successful session yesterday. He placed four 10ps in the machine in order to have four consecutive goes. And the sequence of five different selections of lit-up digits which he observed resulted in him winning all four jackpots.
What number was showing immediately before he put in his first 10p?
This puzzle is included in the book Microteasers (1986).
[teaser1099]

Jim Randell 9:26 am on 2 April 2023 Permalink |
In order to arrive at a unique solution I had to (reasonably) assume that “some of the stars” means “at least 2 of the stars”.
This Python program runs in 63ms. (Internal runtime is 7.8ms).
Run: [ @replit ]
from enigma import (irange, subsets, nconcat, dsum, diff, printf) # possible displayed numbers # = numbers with at least 2 different digits in increasing order ns = list(subsets(irange(1, 9), min_size=2, fn=nconcat)) # record prize pairs prize = { 1: set(), 2: set(), 3: set(), 4: set() } # collect prize numbers for n in ns: tw = 2 * n if tw in ns: prize[1].add((tw, n)) sq = n * n if sq in ns: prize[2].add((n, sq)) prize[3].add((sq, n)) ds = dsum(n) if ds in ns: prize[4].add((n, ds)) # find a sequence of numbers that give prizes in <ks> def solve(ks, ss): if not ks: yield ss else: x = ss[-1] for k in ks: for (y, z) in prize[k]: if x == y and z not in ss: yield from solve(diff(ks, {k}), ss + [z]) # choose a starting pair for (k, vs) in prize.items(): for (a, b) in vs: # solve for the remaining prizes for ss in solve(diff(prize.keys(), {k}), [a, b]): printf("{ss}")Solution: The machine was initially showing: 134689.
So we have:
LikeLike
Frits 6:35 pm on 2 April 2023 Permalink |
Starting from Jim’s program but not using enigma.py and using a dictionary of slot machine numbers .
from itertools import combinations dsum = lambda n: sum(int(x) for x in str(n)) # number of different selections of lit-up digits N = 5 # possible slot machine numbers ns = list(int("".join(str(y) for y in x)) for n in range(2, 10) for x in combinations(range(1, 10), n)) # dictionary of slot machine numbers and following jackpots d = {n : list([0] * (N - 1)) for n in ns} # collect dictionary elements for n in ns: tw = 2 * n if tw in ns: d[tw][0] = n sq = n * n if sq in ns: d[n][1] = sq d[sq][2] = n ds = dsum(n) if ds in ns: d[n][3] = ds # only keep slot machine numbers after which a jackpot may occur d = {k: v for k, v in d.items() if v != [0] * (N - 1)} # find a sequence of N slot machine numbers with N - 1 different jackpots def solve(k, ss, types=[]): if len(ss) == N: yield ss else: for t, v in enumerate(d[k]): # type of jackpot already processed? if t in types: continue if ((len(ss) == N - 1 and v in ns) or v in d): # number may not have been used before if v not in ss: yield from solve(v, ss + [v], types + [t]) # check slot machine numbers after which a jackpot may occur for k in d.keys(): # check if N - 1 different jackpots can follow for ss in solve(k, [k]): print(f"{ss}")LikeLike