

A357272


a(n) is the number of ways n can be calculated with expressions of the form "d1 o1 d2 o2 d3 o3 d4" where d1d4 are decimal digits (09) and o1o3 are chosen from the four basic arithmetic operators (+, , *, /).


2



29235, 12654, 12450, 12425, 12427, 11915, 12419, 11792, 12062, 11725, 8748, 7686, 8180, 6632, 6549, 6077, 5758, 4532, 4915, 3503, 3649, 3451, 2684, 2468, 3253, 2288, 1957, 2347, 2197, 1627, 2028, 1444, 1899, 1439, 1281, 1531, 2080, 1195, 1126, 1147, 1513
(list;
graph;
refs;
listen;
history;
text;
internal format)



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, "34+5*8" is 34+(5*8) = (34)+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 (09*9*9). The last nonzero a(n) is n = 6561 (9*9*9*9).


LINKS



EXAMPLE

a(235) = 9 because 235 may be expressed in nine ways: "3*9*98", "5*6*85", "5*8*65", "6*5*85", "6*8*55", "8*5*65", "8*6*55", "9*3*98", and "9*9*38".


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)]


CROSSREFS



KEYWORD

nonn,base


AUTHOR



STATUS

approved



