OFFSET
0,1
COMMENTS
This sequence is an extension of the "four fours" puzzle.
Expressions follow operator precedence (*/) then (+-), and left to right within the same level of precedence: "5/6/7/8" is ((5/6)/7)/8, "3-4+5*8" is 3-4+(5*8) = (3-4)+40 = -1+40 = 39.
Expressions are treated as ordered, so that 1+2+3+4 is distinct from 1+3+2+4 (but has the same value).
If negative n is allowed, the first nonzero a(n) is n = -729 (0-9*9*9). The last nonzero a(n) is n = 6561 (9*9*9*9).
There are 671 nonzero terms. - Michael S. Branicky, Sep 24 2022
LINKS
Michael S. Branicky, Table of n, a(n) for n = 0..6561
EXAMPLE
a(235) = 9 because 235 may be expressed in nine ways: "3*9*9-8", "5*6*8-5", "5*8*6-5", "6*5*8-5", "6*8*5-5", "8*5*6-5", "8*6*5-5", "9*3*9-8", and "9*9*3-8".
PROG
(Python)
from itertools import product
from fractions import Fraction
from collections import Counter
def afull(): # all further terms are 0
a = Counter()
for digs in product("0123456789", repeat=4):
for ops in product("+-*/", repeat=3):
e = digs[0] + "".join(ops[i] + digs[i+1] for i in range(3))
if "/0" in e: continue
if "/" in e:
for d in set(digs): e = e.replace(d, f"Fraction({d}, 1)")
t = eval(e)
if t >= 0 and t.denominator == 1: a[t] += 1
return [a[n] for n in range(max(a)+1)]
print(afull()[:100]) # Michael S. Branicky, Sep 24 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rod McFarland, Sep 22 2022
STATUS
approved