| Bytes | Lang | Time | Link |
|---|---|---|---|
| 013 | Vyxal 3 | 250828T091003Z | Themooni |
| 044 | TIBASIC TI83 Plus | 250403T192040Z | madeforl |
| 008 | iogii | 250105T184737Z | Darren S |
| 191 | Bespoke | 250119T211233Z | Josiah W |
| 010 | Japt | 250118T180938Z | Shaggy |
| 053 | Bash | 240605T145321Z | Themooni |
| 135 | Brainfuck | 240605T133256Z | 12431234 |
| 059 | Python 3 | 240607T224958Z | dan04 |
| 065 | Retina 0.8.2 | 240606T104717Z | Neil |
| 052 | R | 240604T194620Z | Glory2Uk |
| 060 | Haskell | 240605T225144Z | corvus_1 |
| 050 | R lower than version 4.1 | 240604T193605Z | Giuseppe |
| 045 | Perl 5 | 240605T143643Z | Xcali |
| 007 | 05AB1E | 240605T072431Z | Kevin Cr |
| 054 | Python 3.8 prerelease | 240605T065610Z | Jitse |
| 038 | Ruby | 240604T211646Z | AZTECCO |
| 7259 | Uiua | 240605T063102Z | mousetai |
| 012 | Charcoal | 240605T072638Z | Neil |
| 090 | Google Sheets | 240604T234039Z | z.. |
| 044 | PowerShell Core | 240604T200201Z | Julian |
| 010 | Jelly | 240604T172656Z | Jonathan |
| 047 | JavaScript V8 | 240604T155500Z | Arnauld |
| 024 | ><> Fish | 240604T155826Z | mousetai |
Vyxal 3, 13 bytes
⎄¥#¤C:[¥›£|0£
⎄¥#¤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.
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
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:
- It uses negative addresses. Not all interpreter and compilers accept that. If that is not acceptable, add
>>>>>(not sure how many you exaclty need) at the beginning. - With 8 bit cells only the first 285 are correct. With larger cells, more values will be correct. With infinite large cells and a infinite amount of cells, it should print infinite correct values.
- It outputs it as raw integers. Don't expect any ASCII values.
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.
- Member 0,
moveData: Used to move data from one struct to struct 0 and to move M struct's forward (where M is the number we last printed). So we increase the counter in the correct struct - Member 1,
temp: Used to temporarely copy data to. To be able to copy data from one cell to a other and then restoring the source. - Member 2,
counter: How many times we printed N (Where N is struct index we are currently on). - Member 3,
structPrinted: Is set when we start printing the number of the current struct. Cleared after we printed 0. - Member 4,
useThisStruct: Set in all used struct's. Used to find struct 0. This value is incrementd multiple time but never decremented (to reduce code), with a limited cell size, this means that this will overflow and generate wrong values (reason for the 285 limit with 8 bit cells).
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}
R, 60 56 52 bytes
- -4 bytes thanks to the pajonk's suggestion
`?`=\(F,N){show(x<-sum(F==N));(F+1)*!!x?c(N,x)};0?{}
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.
For the sequence elements the constant
Fis used, which has been set toFALSE(==0) by defaultThe number of occurences is calculated inside of the
showas a sum of booleansIn the last statement
Fbecomes 0 or adds 1.
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.
R (lower than version 4.1), 50 bytes
p={}
repeat F="if"(p<-c(print(sum(p==F)),p),F+1,0)
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)
Function version that prints out the first \$n\$ terms.
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.
Original 11 bytes approach:
0λλ¾¢¼D_i.µ
Outputs the infinite sequence.
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
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
Full program that prints the first 2974 entries and then halts
Uiua, 42 37 chars, 72 59 bytes
◌:∧(⊂:⟜(:⟨-.:|+1:⟩±)/+=,,°□◌)⇡250□[]0
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++}
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’ċ@ṭµ¡Ḋ
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])
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
Hover over any symbol to see what it does
Unformatted:
5:1g:n::1g1+$1p0):@*+ao!