A342585 Inventory sequence: record the number of zeros thus far in the sequence, then the number of ones thus far, then the number of twos thus far and so on, until a zero is recorded; the inventory then starts again, recording the number of zeros.
0, 1, 1, 0, 2, 2, 2, 0, 3, 2, 4, 1, 1, 0, 4, 4, 4, 1, 4, 0, 5, 5, 4, 1, 6, 2, 1, 0, 6, 7, 5, 1, 6, 3, 3, 1, 0, 7, 9, 5, 3, 6, 4, 4, 2, 0, 8, 9, 6, 4, 9, 4, 5, 2, 1, 3, 0, 9, 10, 7, 5, 10, 6, 6, 3, 1, 4, 2, 0, 10, 11, 8, 6, 11, 6, 9, 3, 2, 5, 3, 2, 0, 11, 11, 10
Offset: 1
Examples
As an irregular triangle this begins: 0; 1, 1, 0; 2, 2, 2, 0; 3, 2, 4, 1, 1, 0; 4, 4, 4, 1, 4, 0; 5, 5, 4, 1, 6, 2, 1, 0; 6, 7, 5, 1, 6, 3, 3, 1, 0; 7, 9, 5, 3, 6, 4, 4, 2, 0; 8, 9, 6, 4, 9, 4, 5, 2, 1, 3, 0; 9, 10, 7, 5, 10, 6, 6, 3, 1, 4, 2, 0; 10, 11, 8, 6, 11, 6, 9, 3, 2, 5, 3, 2, 0; ... For row lengths see A347299. - _N. J. A. Sloane_, Aug 27 2021 From _David James Sycamore_, Oct 18 2021: (Start) a(1) is 0 because the count is reset, and as yet there is no zero term immediately following another term. a(2) = 1 since the count is reset, a(1) = 0 and a(0) precedes it. The count now increments to terms equal to 1. a(3) = 1 since a(2) = 1 and a(1) precedes it. a(4) = 0 because there is no term equal to 2 which is immediately preceded by another term. a(5) = 2 since the count is reset, a(1) = a(4) = 0 and a(0), a(3) respectively, precede them. (End)
Links
- Rémy Sigrist, Table of n, a(n) for n = 1..25000
- Brady Haran and N. J. A. Sloane, "A Number Sequence with Everything" (the Inventory Sequence A342585), Numberphile video, November 2022.
- Hans Havermann, Colored plot of 1000467 terms [See Comments for a description of this plot]
- Hugo Pfoertner, Listening to the first 100000 terms of A342585, YouTube video from "Talabfahrer".
- Hugo Pfoertner, Hear 1 million terms of A342585, YouTube video from "Talabfahrer", alternative audio conversion.
- Luc Rousseau, AWK program for A342585
- Rémy Sigrist, Scatterplot of the first 10^6 terms
- Rémy Sigrist, Scatterplot of the first 10^7 terms
- Rémy Sigrist, Scatterplot of the first 10^8 terms
- Rémy Sigrist, Table of n, a(n) for n = 1..100000
- Rémy Sigrist, PARI program for A342585
- Jan Ritsema van Eck, Graph #1: 1000 terms (blue) and inverse triangular numbers A003056 (orange)
- Jan Ritsema van Eck, Graph #2: 10000 terms (blue) and inverse triangular numbers A003056 (orange)
- N. J. A. Sloane, "A Handbook of Integer Sequences" Fifty Years Later, arXiv:2301.03149 [math.NT], 2023, p. 21.
- Index entries for sequences related to the inventory sequence
Crossrefs
Programs
-
AWK
# See Links section. - Luc Rousseau, May 02 2021
-
MATLAB
function [val,arr]=invSeq(N) % val = Nth term, arr = whole array up to N k=0; arr=zeros(1,N); % pre-allocate array for i=1:N an=sum((k==arr(2:i))); arr(i)=an; if an == 0 k = 0; else k=k+1; end end val=arr(end); end % Ben Cha, Nov 11 2022
-
Maple
a:= proc(n) option remember; local t; t:= `if`(a(n-1)=0, 0, b(n-1)+1); b(n):=t; add(`if`(a(j)=t, 1, 0), j=1..n-1) end: b(1), a(1):= 0$2: seq(a(n), n=1..120); # Alois P. Heinz, Mar 16 2021
-
Mathematica
a[n_] := a[n] = Module[{t}, t = If[a[n-1] == 0, 0, b[n-1]+1]; b[n] = t; Sum[If[a[j] == t, 1, 0], {j, 1, n-1}]]; b[1] = 0; a[1] = 0; Array[a, 120] (* Jean-François Alcover, May 03 2021, after Alois P. Heinz *)
-
PARI
A342585_vec(N,c=[],i)=vector(N,j, while(#c<=i||#c<=c[i+1], c=concat(c,0)); c[i+=1]+if(c[1+c[i]]++&&!c[i]||j==1,i=0)) \\ M. F. Hasler, Nov 13 2021
-
PARI
\\ See Links section.
-
Python
def calc(required_value_number): values_lst = [] current_count = 0 new_value = 0 for i in range(required_value_number): new_value = values_lst.count(current_count) values_lst.append(new_value) if new_value == 0: current_count = 0 else: current_count += 1 return new_value # Written by Gilad Moyal
-
Python
from collections import Counter def aupton(terms): num, alst, inventory = 0, [0], Counter([0]) for n in range(2, terms+1): c = inventory[num] num = 0 if c == 0 else num + 1; alst.append(c); inventory.update([c]) return alst print(aupton(84)) # Michael S. Branicky, Jun 12 2021
-
R
# Prints the first 10,068 terms library("dplyr") options(max.print=11000) inventory <- data.frame(1, 0) colnames(inventory) <- c("n", "an") value_to_count = 0 n = 1 for(x in 1:128) # Increase the 128 for more terms. The number of terms # given is on the order of x^1.9 in the region around 128. { status <- TRUE while(status) { count <- length(which(inventory$an == value_to_count)) n = n + 1 inventory <- rbind(inventory, c(n, count)) status <- isTRUE(count != 0) value_to_count = value_to_count + 1 } value_to_count = 0 } inventory # Damon Lay, Nov 10 2023
Comments