cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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 d1-d4 are decimal digits (0-9) and o1-o3 are chosen from the four basic arithmetic operators (+, -, *, /).

This page as a plain text file.
%I A357272 #39 Nov 10 2022 12:36:09
%S A357272 29235,12654,12450,12425,12427,11915,12419,11792,12062,11725,8748,
%T A357272 7686,8180,6632,6549,6077,5758,4532,4915,3503,3649,3451,2684,2468,
%U A357272 3253,2288,1957,2347,2197,1627,2028,1444,1899,1439,1281,1531,2080,1195,1126,1147,1513
%N 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 d1-d4 are decimal digits (0-9) and o1-o3 are chosen from the four basic arithmetic operators (+, -, *, /).
%C A357272 This sequence is an extension of the "four fours" puzzle.
%C A357272 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.
%C A357272 Expressions are treated as ordered, so that 1+2+3+4 is distinct from 1+3+2+4 (but has the same value).
%C A357272 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).
%C A357272 There are 671 nonzero terms. - _Michael S. Branicky_, Sep 24 2022
%H A357272 Michael S. Branicky, <a href="/A357272/b357272.txt">Table of n, a(n) for n = 0..6561</a>
%e A357272 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".
%o A357272 (Python)
%o A357272 from itertools import product
%o A357272 from fractions import Fraction
%o A357272 from collections import Counter
%o A357272 def afull(): # all further terms are 0
%o A357272     a = Counter()
%o A357272     for digs in product("0123456789", repeat=4):
%o A357272         for ops in product("+-*/", repeat=3):
%o A357272             e = digs[0] + "".join(ops[i] + digs[i+1] for i in range(3))
%o A357272             if "/0" in e: continue
%o A357272             if "/" in e:
%o A357272                 for d in set(digs): e = e.replace(d, f"Fraction({d}, 1)")
%o A357272             t = eval(e)
%o A357272             if t >= 0 and t.denominator == 1: a[t] += 1
%o A357272     return [a[n] for n in range(max(a)+1)]
%o A357272 print(afull()[:100]) # _Michael S. Branicky_, Sep 24 2022
%K A357272 nonn,base
%O A357272 0,1
%A A357272 _Rod McFarland_, Sep 22 2022