g | x | w | all
Bytes Lang Time Link
013Vyxal 3250828T091003ZThemooni
044TIBASIC TI83 Plus250403T192040Zmadeforl
008iogii250105T184737ZDarren S
191Bespoke250119T211233ZJosiah W
010Japt250118T180938ZShaggy
053Bash240605T145321ZThemooni
135Brainfuck240605T133256Z12431234
059Python 3240607T224958Zdan04
065Retina 0.8.2240606T104717ZNeil
052R240604T194620ZGlory2Uk
060Haskell240605T225144Zcorvus_1
050R lower than version 4.1240604T193605ZGiuseppe
045Perl 5240605T143643ZXcali
00705AB1E240605T072431ZKevin Cr
054Python 3.8 prerelease240605T065610ZJitse
038Ruby240604T211646ZAZTECCO
7259Uiua240605T063102Zmousetai
012Charcoal240605T072638ZNeil
090Google Sheets240604T234039Zz..
044PowerShell Core240604T200201ZJulian
010Jelly240604T172656ZJonathan
047JavaScript V8240604T155500ZArnauld
024><> Fish240604T155826Zmousetai

Vyxal 3, 13 bytes

⎄¥#¤C:[¥›£|0£

Vyxal It Online!

⎄¥#¤C:[¥›£|0£­⁡​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌⁢​‎⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏‏​⁡⁠⁡‌­
⎄             # ‎⁡generator:
    C          # ‎⁢count...
 ¥             # ‎⁣register in...
  #¤           # ‎⁤previously generated.
     :[        # ‎⁢⁡if it's not 0,
       ¥›£     # ‎⁢⁢increment the register
          |0£  # ‎⁢⁣else set it to 0
💎

Created with the help of Luminespire.

<script type="vyxal3">
⎄¥#¤C:[¥›£|0£   ]250⊖
</script>
<script>
    args=[]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

TI-BASIC (TI-83 Plus), 56 48 44 bytes

For(L,1,ᴇ3
sum(L₁=I→N
Disp N
L→dim(L₁
N→L₁(L
(I+1)not(not(N→I
End

prints every number on a new line

iogii, 8 bytes

Ewsq_c>h

Try it! (also has parse graph and ir graph)

This was a fun problem in iogii since iogii is purely functional and the description of the algorithm is very imperative, but it ended up being too simple! Was hoping to use it as a good example of how to do imperative things.

This approach builds an infinite list of the reversed prefixes of the answer. Calculating the index is just the length of the number of leading truthy elements.

E     # expand (iterate starting from [], and capitalized means on a list instead of scalar)
   w  # takeWhile using implicit loop var since stack is empty and it takes two args
   s  # size (length). This is essentially the "index" it is length of last non zeros values
   q  # equal
   _  # sum (the count of equal elements since equal returns 1 or 0)
   c  # cons this prepends the result to the list before it
>     # end block (end expand)
h     # head, since we only want the value that was consed at each iteration

Bespoke, 191 bytes

keep X-Y-Z counted
firstly is zero
N=O,so zero output
N=one,so one is output&so on
soon,if zero=N I returned,restart
so nicely I do my work
however,is it a salaried service
somehow got paid$O

This is a pretty nice application for the heap; the number of times n was output is stored at the nth address on the heap.

Japt, 10 bytes

Outputs the first n terms. Adapted from the 05AB1E solution.

@Zè¶ZÔbT}h

Try it

Bash, 53 bytes

-21 bytes by @12431234123412341234123 and myself:

By removing the loop condition (and run infinitely, which I had feelings about), I also get to use for instead of while, which means i get to use {} instead of do...done.
I also get to remove the i=0 assignment.
Separately, i get to remove :>a (which creates the file) by using tee to create the file.
The remaining byte save is simple golfing like avoiding assigning a variable and instead using tthe output of grep directly.

-7 bytes by @12431234123412341234123 by using grep -w instead of grep ^$i$, and by using recursive functions instead of a for loop

-1 byte by me by using <1 instead of ==0

0()(((`grep -wc $i a|tee -a a`<1))&&i=0||let i++
0);0

Attempt This Online!

Previous Version

Previous Previous Version

explanation:

0()(                                                 #declare a function named "0"
       grep -wc $i a                                 #find and count all instances of our index in file "a"
                    |tee -a a                        #copy standard output and append it to file "a"
    ((`                      `<1))                   #test if standard output of previous is ==0 (since we never have negative numbers, <1 is equivalent to ==0).
                                   &&i=0||let i++    #if so, i=0, increment otherwise
0                                                    #call function "0", looping infinitely
 );0                                                 #end function declaration, then call 0 the first time.

use as a function body or script, runs infinitely. outputs to a file named "a" in the current directory.

I've verified the first 85 elements (this is what OEIS stores) are correct, but I don't see why it wouldn't keep being correct.

Brainfuck, 135 Byte

+[<+<[.[-<+<+>>]<[->+<]<<[>[-<<<<<+>>>>>]<<<<<<]>[[->>>>>+<<<<<]>>>>>>>>>+<<<<-]>>+<<<[<<<<<]>>>>[>>>>>]+<].<<<[>>>>-<<<<<<<<<]>>>+>->]

Some Notes:

Explanation

The cells are combined to blocks or structs of 5 Cells. Similar to a C array of struct with 5 members per struct. Each struct has this Members.

Note, we start with Member 4, useThisStruct. This means we use negative offests and the cell index doesn't align with the struct's.

+  Set useThisStruct since we use struct 0

[ "Infinite" loop; useThisStruct of struct 0 should be non 0

    <+ Set structPrinted since we are about to print the value
    <[ Loop we run till the next value we should print is 0
        .   Print counter of the current struct
        
        [-<+<+>>]<[->+<] Copy counter to moveData while using temp to restore counter after copying

        <<[>[-<<<<<+>>>>>]<<<<<<] Move the value of moveData of the current struct to moveData of struct at Index 0

        >[[->>>>>+<<<<<]>>>>>>>>>+<<<<-] Move to struct at index moveData
        >>+ Increase the counter in this block

        <<<[<<<<<] Move back to struct 0
        >>>>[>>>>>] Move to the next struct we should print
        + Set structPrinted since we are about to print the value
    <] Loop till counter is 0


    .  Print counter which is 0
    <<<[>>>>-<<<<<<<<<]>>>+ Go back to struct 0 and reset structPrinted in every struct
    >-> Set counter in struct 0 to 1

]

Previous versions

137 Byte

+[<+<[.[-<+<+>>]<[->+<]<<[>[-<<<<<+>>>>>]<<<<<<]>[[->>>>>+<<<<<]>>>>>>>>>+<<<<-]>>+<<<[<<<<<]>>>>[>>>>>]+<].<<<[>>>>-<<<<<<<<<]>>>>-<+>>]

144 Byte version

+[<+<[.<<[-]>>[-<+<+>>]<[->+<]<<[>[-<<<<<+>>>>>]<<<<<<]>[[->>>>>+<<<<<]>>>>>>>>>+<<<<-]>>+<<<[<<<<<]>>>>[>>>>>]+<].<<<[>>>>-<<<<<<<<<]>>>>-<+>>]

180 Byte version

+[>+<<<[.>>>>[-]<<<<[->+>>>+<<<<]>[-<+>]<<<<[>>>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<]>>>>>>>[[->>>>>+<<<<<]>>>+>>-]<<<<+<<<[<<<<<]>>>>>>[>>>>>]+<<<].<<<[>>>>>>-<<<<<<<<<<<]>>>>>>-<<<+>>]

202 Byte version

+<<<+[>>>>+<<<[.>>>>[-]<<<<[->+>>>+<<<<]>[-<+>]<<<<[>>[-]>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<]>>>>>>>[>>>>>[-]<<<<<[->>>>>+<<<<<]>>>+>>-]<<<<+<<<[<<<<<]>>>>>>[>>>>>]+<<<].<<<[>>>>>>-<<<<<<<<<<<]>>>>>>-<<<+<]

211 Byte Version

+<+[>>>>+<[.>>[-]<<[-<+>>>+<<]<[->+<]<<<<<<[>>>>[-]>>>>>[-<<<<<+>>>>>]<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>[-]<<<<<[->>>>>+<<<<<]>+>>>>-]<<+<<<<<<<[<<<<<]>>>>>>>>[>>>>>]+<].<<<<<<<[>>>>>>>>-<<<<<<<<<<<<<]>>>>>>>>-<+<<<]

Python 3, 59 bytes

i=0;a=[0]*99
while 1:print(n:=a[i]);a[n]+=1;i=[i+1,0][n==0]

This is a mostly straightforward golfing of OP's program, with i = index, n = nextNumber, and a[i] being the number of times i has already been printed.

Retina 0.8.2, 65 bytes

.+
$*_
smr{1`(^0((¶)|.)*?¶)?_
$1$#3¶_
(((^\4$)|.)*)(\d+)¶_
$1$#3¶

Try it online! Outputs the first N terms. Explanation:

.+
$*_

Convert the input to unary, but using _ instead of the default 1, which would otherwise be confusing.

smr`

Process the rest of the script in single-line (. matches newlines), multiline (^$ match on each line) and right-to-left (regex starts matching at the end of the output buffer and works backwards) modes.

{`

Repeat until N is reduced to zero.

1`(^0((¶)|.)*?¶)?_
$1$#3¶_

Append the offset of the last appearance of 0 on its own line. (A $ isn't needed here because 0 is the only non-negative integer that begins with 0.) The extra 1`(...¶)? seems to be the golfiest way to deal with the edge case of the first pass through the loop.

(((^\4$)|.)*)(\d+)¶_
$1$#3¶

Count the number of times that the offset has already appeared in the sequence, replace the offset with that count, and decrement N.

R, 56 52 bytes

N={};repeat{show(x<-sum(F==N));N=c(N,x);F=(F+1)*!!x}

Attempt This Online!

R, 60 56 52 bytes

`?`=\(F,N){show(x<-sum(F==N));(F+1)*!!x?c(N,x)};0?{}

Attempt This Online!

Edit: -4 bytes were removed in both cases by teplacing an if with an arithmetical expression. The old code is still available and linked to the respective byte count.

Here are two full programs: the first one runs a forever loop (repeat conveniently requires no arguments for that) and another one is based on a recursive function without an exit condition.

Haskell, 60 bytes

g[]0
g a i|let c=sum[1|x<-a,x==i]=c:g(c:a)(last$0:[i+1|c>0])

Prints the sequence indefinitely.

Attempt This Online!

R (lower than version 4.1), 50 bytes

p={}
repeat F="if"(p<-c(print(sum(p==F)),p),F+1,0)

Try it online!

Prints indefinitely (or until R runs out of memory). p would contain the printed values in reverse, since if defaults to take the first element as its condition (with a warning), in versions 4.1 and lower.

R, 67 bytes

function(n,p={})for(i in 1:n)F="if"(p<-c(print(sum(p==F)),p),F+1,0)

Try it online!

Function version that prints out the first \$n\$ terms.

Perl 5, 45 bytes

{{$a[$_=$a[$i++]|0]++;say;$_&&redo}$i=0;redo}

Try it online!

05AB1E, 11 7 bytes

0λλÂ0k¢

-4 bytes porting @JonathanAllan's Jelly approach, so make sure to upvote that answer as well!

Outputs the infinite sequence.

Try it online.

Original 11 bytes approach:

0λλ¾¢¼D_i.µ

Outputs the infinite sequence.

Try it online.

Explanation:

 λ          # Start a recursive environment,
            # to calculate the infinite sequence
0           # Starting with a(0)=0
            # Where every following a(n) is calculated as:
  λ         #  Push all terms thus far: [a(0),a(1),...,a(n-1)]
   Â        #  Bifurcate it; short for Duplicate & Reverse copy
    0k      #  Pop and get the first 0-based index of item 0 in this reversed copy
      ¢     #  Count how many times this index occurs in the terms thus far
   
 λ          # Start a recursive environment,
            # to calculate the infinite sequence
0           # Starting with a(0)=0
            # Where every following a(n) is calculated as:
  λ         #  Push all terms thus far: [a(0),a(1),...,a(n-1)]
   ¾¢       #  Count how many times the counter variable `¾` occurs in it
            #  (`¾` starts at 0 by default)
     ¼      #  Increase the counter variable `¾` by 1 for the next iteration
     D      #  Duplicate this count
      _i    #  Pop the copy, and if it's 0:
        .µ  #   Reset counter variable `¾` back to 0 for the next iteration

Python 3.8 (pre-release), 54 bytes

i,*a=0,
while[print(x:=a.count(i))]:i,*a=x and-~i,*a,x

Try it online!

Full program that prints indefinitely


Python 3.8 (pre-release), 52 bytes

a=[i:=0]*99
while[print(x:=a[i])]:i=x and-~i;a[x]+=1

Try it online!

Full program that prints the first 2974 entries and then halts

Ruby, 44 38 bytes

$*<<B while$_=0<(B=p$*.count$_)?$_+1:0

Try it online!

Uiua, 42 37 chars, 72 59 bytes

◌:∧(⊂:⟜(:⟨-.:|+1:⟩±)/+=,,°□◌)⇡250□[]0

Try it

I've literally never written program in Uiua before so it's probably nowhere near efficient.

Charcoal, 12 bytes

FN⊞υ№υ⌕⮌υ⁰Iυ

Try it online! Link is to verbose version of code. Outputs the first N terms. Explanation: Port of @JonathanAllan's Jelly answer. Explanation:

FN

Repeat N times.

⊞υ№υ⌕⮌υ⁰

Find the position of 0 in the reversed list so far, and push the count of that position in the list to the list.

Iυ

Output the final list.

Google Sheets, 90 bytes

=LET(R,LAMBDA(R,l,v,i,LET(c,COUNTIF(l,v),IF(i=250,l,R(R,{l;c},(c>0)*(v+1),i+1)))),R(R,,,))

Commented

=LET(
   R,LAMBDA(R,l,v,i,        // define a recursive function R(R,l,v,i) where `l` is the list, `v` is the current value and `i` is the current iteration
     LET(c,COUNTIF(l,v),    // assign to `c` the count of the current value `v` in the list of values `l`
        IF(i=250,           // base case: if we reached 250 iterations... 
           l,               // ...return the list
           R(R,             // recursive case: execute the function R(R,l,v,i)... 
            {l;c},          // ...where the new list is `c` appended to `l`, 
            (c>0)*(v+1),    // the new value is 0 if the count is 0 or incremented by 1 otherwise, 
            i+1)))),        // the new iteration is the current iteration + 1
   R(R,,,))                 // execute the function

PowerShell Core, 44 bytes

for($s=@{}){($l=+$s.($i=++$i*!!$l))
$s.$l++}

Try it online!

Outputs the sequence indefinitely

for($s=@{}){   # Main loop, initialises the inventory `$s` to an empty object
($l=+$s.+$i)   # Get the state of the inventory at the current index `$i`, print and store in `$l`
$s.$l++        # Increment the inventory for the last printed value
$i=++$i*!!$l}  # if the last printed number `$l` was 0, reset the index to 0, increment it otherwise

Jelly, 10 bytes

Ṛi0’ċ@ṭµ¡Ḋ

Try it online!

A monadic Link accepting the number of terms, N, to produce and yielding a list of the first N terms.

How?

Ṛi0’ċ@ṭµ¡Ḋ - Link: non-negative integer, N
        ¡  - repeat this N times (do it N+1 times):
       µ   -   monadic chain - f(A=current list or the initial integer, N):
Ṛ          -     reverse A (N becomes [N])
 i0        -     first 1-indexed index of zero in that; 0 if not found
   ’       -     decrement that
    ċ@     -     count occurrences in A
      ṭ    -     tack that to A (ready for the next iteration)
         Ḋ - dequeue (remove the leading N)

Note that leading \$N\$ is guaranteed to never be counted due to it simply being too large (we only have that number of terms on the final iteration however, the list at that point starts N, 0 so the only edge case to check is \$N=1\$).

JavaScript (V8), 47 bytes

A full program that prints the sequence indefinitely.

for(o=[v=0];;o[v]=-~o[v])print(v=~~o[n=v&&n+1])

Try it online!

Commented

for(            // loop:
  o = [         //   o = object to count how many times
                //       each value was printed
    v = 0       //   v = last printed value
  ];            //
  ;             //   no stop condition (loop forever)
  o[v] = -~o[v] //   increment o[v] after each iteration
)               //
  print(        //   print:
    v = ~~o[    //     the new value v = o[n]
      n = v &&  //     where n is set to 0 if v = 0
          n + 1 //     or incremented otherwise
    ]           //
  )             //

><> (Fish), 24 bytes

5:1g:n::1g1+$1p0):@*+ao!

Hover over any symbol to see what it does

Unformatted:

5:1g:n::1g1+$1p0):@*+ao!

Try it