OFFSET
1,2
LINKS
Gilles Bannay, Countdown Problem
EXAMPLE
a(4)=11 because we can write 4+1=5, 4+2=6, 4+2+1=7, 4*2=8, 4*2+1=9, (4+1)*2=10 by using 1, 2 and 4, but we cannot construct 11 this way.
a(7)=1143 because 1142 = (152+((34-4)*(11*(2+1)))), and 1143 is impossible.
a(7) is not 1007 because it can be constructed as 1007 = 152*(11-(34+1)/(4*2)); the fractional intermediate result 35/8, for example, is accepted in the composition.
PROG
(Python)
from fractions import Fraction
def a(n, v):
R = dict() # index of each reachable subset is [card(s)-1][s]
for i in range(n): R[i] = dict()
for i in range(n): R[0][(v[i], )] = {v[i]}
reach = set(v)
for j in range(1, n):
for i in range((j+1)//2):
for s1 in R[i]:
for s2 in R[j-1-i]:
if set(s1) & set(s2) == set():
s12 = tuple(sorted(set(s1) | set(s2)))
if s12 not in R[len(s12)-1]:
R[len(s12)-1][s12] = set()
for a in R[i][s1]:
for b in R[j-1-i][s2]:
allowed = [a+b, a*b, a-b, b-a]
if a != 0: allowed.append(Fraction(b, a))
if b != 0: allowed.append(Fraction(a, b))
R[len(s12)-1][s12].update(allowed)
reach.update(allowed)
k = 1
while k in reach: k += 1
return k
alst = [1]
[alst.append(a(n, alst)) for n in range(1, 6)]
print(alst) # Michael S. Branicky, Jul 01 2022
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Clément Morelle, Sep 25 2012
STATUS
approved