| Bytes | Lang | Time | Link |
|---|---|---|---|
| 003 | Vyxal 3 | 250425T075910Z | Themooni |
| 030 | Swift 6 | 250425T012245Z | macOSist |
| 020 | TIBASIC TI83 Plus | 250424T170546Z | madeforl |
| 024 | AWK | 250313T203938Z | xrs |
| 055 | SAKO | 250327T162115Z | Acrimori |
| 003 | Regenerate a | 250127T175246Z | Unrelate |
| 005 | cQuents | 250128T041305Z | Stephen |
| 010 | Retina 0.8.2 | 201130T224637Z | Neil |
| 006 | Japt | 250126T220400Z | Shaggy |
| 024 | CASIO BASIC CASIO fx9750GIII | 250126T214828Z | madeforl |
| 019 | Bash | 201203T204154Z | Adam Kat |
| nan | 230219T163151Z | The Thon | |
| 003 | Vyxal | 230219T165556Z | The Thon |
| 007 | Pyt | 230202T015344Z | Kip the |
| 016 | Appleseed | 220726T033125Z | DLosc |
| 076 | Python | 220725T235100Z | Eric Xue |
| 005 | Vyxal | 220724T231403Z | aketon |
| 014 | Regenerate a | 220703T020331Z | Deadcode |
| 050 | Rust | 210302T164310Z | Aiden4 |
| 020 | PowerShell | 210302T090434Z | wasif |
| 127 | Batch | 210302T083726Z | wasif |
| 051 | Chapel | 210123T224706Z | sech1p |
| 070 | Scratch 3.0 | 201130T210335Z | lyxal |
| 016 | sed in unary | 210123T100409Z | user4180 |
| 076 | Java OpenJDK 8 | 210123T102735Z | user1004 |
| 036 | Python 3 | 210123T054037Z | Berken T |
| 1715 | convey | 201214T192032Z | xash |
| 033 | AWK | 201224T214609Z | Pedro Ma |
| 034 | Arm Thumb with libc calls | 201224T163030Z | EasyasPi |
| 025 | Wolfram Language Mathematica | 201130T182053Z | ZaMoC |
| 020 | Perl 5 | 201130T195126Z | Xcali |
| 014 | PowerShell Core | 201224T020006Z | Julian |
| 027 | convey | 201217T232141Z | Wheat Wi |
| 056 | Common Lisp | 201217T223443Z | Byte |
| 047 | Nim | 201215T074146Z | xigoi |
| 019 | Zsh | 201201T114000Z | roblogic |
| 046 | Julia | 201202T162443Z | Amir rez |
| 024 | jq | 201203T220753Z | Esolangi |
| 054 | Java JDK | 201203T010454Z | branboye |
| 043 | Rust + rand crate | 201201T090915Z | Patiga |
| 006 | Burlesque | 201202T165335Z | Mintable |
| 061 | Java JDK | 201130T201335Z | DMiddend |
| 036 | AutoHotkey | 201201T222731Z | Engineer |
| 027 | Julia | 201202T150226Z | MarcMush |
| 005 | Befunge | 201202T031823Z | Pizgenal |
| 018 | Raku | 201202T000722Z | Sean |
| 017 | Haskell | 201130T233851Z | xnor |
| 021 | R | 201201T083655Z | Dominic |
| 021 | R | 201130T230646Z | Giuseppe |
| 046 | Icon | 201201T080144Z | Galen Iv |
| 024 | R | 201130T185911Z | Robin Ry |
| 004 | Pyth | 201201T045745Z | Mukundan |
| 031 | Wolfram Language Mathematica | 201201T081835Z | Greg Mar |
| 031 | Python 2 | 201201T072608Z | xnor |
| 044 | C gcc | 201130T182644Z | Noodle9 |
| 040 | JavaScript Browser | 201201T062906Z | tsh |
| 026 | JavaScript V8 | 201201T054222Z | Nina Lis |
| 020 | Bash | 201201T045110Z | Mukundan |
| 032 | Factor | 201201T022610Z | Bubbler |
| 029 | JavaScript V8 | 201201T022518Z | Sisyphus |
| 034 | JavaScript V8 | 201130T180031Z | Arnauld |
| 005 | Stax | 201201T020001Z | Razetime |
| 030 | PHP | 201201T014553Z | Sisyphus |
| 043 | C gcc | 201201T010407Z | Sisyphus |
| 008 | Charcoal | 201130T230022Z | Neil |
| 017 | Ruby | 201201T005917Z | Sisyphus |
| 054 | Rust | 201201T002917Z | Edgar Lu |
| 011 | APL Dyalog Unicode | 201130T181839Z | user |
| 034 | AWK | 201130T213830Z | Noodle9 |
| 028 | Octave | 201130T192803Z | Luis Men |
| 013 | J | 201130T200000Z | Jonah |
| 033 | Python 2 | 201130T180851Z | Noodle9 |
| 004 | Brachylog | 201130T184047Z | Unrelate |
| 004 | Jelly | 201130T175827Z | caird co |
| 020 | sed 4.2.2 | 201130T182907Z | Digital |
| 020 | Bash + GNU Coreutils | 201130T181844Z | Digital |
| 002 | Husk | 201130T181831Z | caird co |
| 002 | 05AB1E | 201130T181406Z | ovs |
| 023 | Scala | 201130T180111Z | user |
Vyxal 3, 3 bytes
kNP
kNP
kN # infinite list of all natural numbers
P # prefixes
💎
Created with the help of Luminespire.
<script type="vyxal3">
kNP100⊖
##note 100⊖ is support code to only output first 100, otherwise it will never stop executing
##and the snippet really doesn't like it
</script>
<script>
args=[]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
TI-BASIC (TI-83 Plus), 20 bytes
both of these require the program to be named "B"
For(B,1,A
Disp B
End
A+1→A
prgmB
TI-BASIC (TI-83 Plus), 18 bytes
you can't see beyond 7 items with this but trust me its doing it
Disp seq(K,K,1,A
A+1→A
prgmB
recursiveness!!!!
SAKO, 55 bytes
**)DRUKUJ(9,0):I
POWTORZ:I=1(1)J
POWTORZ:J=1(1)0
KONIEC
Just uses two simple nested loops.
For numbers longer than 10 characters prints in E notation. Pluses serve as delimiters.
Regenerate -a, 4 3 bytes
*1+
-1 with the leading quantifier trick I learned from an older answer I saw a couple days ago--can't remember whether it was by DLosc, Deadcode, or someone else
Unary output. Leverages the built-in shared repetition limit as an ever-increasing \$n\ge0\$ by which to index into the antidiagonals of an infinite matrix where every row is \$\mathbb{N}\$--the leading * and the trailing + must always repeat their operands a sum of \$n+1\$ times in any given generation, where the \$+1\$ is because + is implemented such that its guaranteed first repetition doesn't count against the repetition limit.
Regenerate -a, 8 7 bytes
( +)+#1
Decimal, and uses the repetition limit in a somewhat more complicated way with nested quantifiers, computing every ordered integer partition of \$n+1\$ and outputting only the last element of each. At repetition limit \$n\$, every generated line contains exactly \$n+1\$ spaces, but on each generation #1 only counts the number of spaces in the last iteration of the capture group. (It doesn't actually have to do this, granted, but this is how I wrote it first and it is pretty fun.)
A unary solution which leverages partitions, if not in quite the same way, is [1 ]+ for 5 bytes.
See the edit history for a variety of older explanations which may be of interest.
cQuents, 5 bytes
b$
&$
Outputs in the format [1],[1, 2],[1, 2, 3],[1, 2, 3, 4], ...
Explanation
b$ first line
implicit `:` mode sequence, output terms infinitely
each term equals
b second line ( )
$ current index
&$ second line
& mode sequence 2, given n output the first n terms in the sequence
each term equals
$ current index
Retina 0.8.2, 11 10 bytes
_
}*!&`_+
Try it online! Outputs in unary. Explanation: The first two lines cause the number of _s to increase on each pass, while the !&`_+ generates all suffixes, which ensures that all integers get printed. The } causes the entire script to repeat indefinitely. The * causes the suffixes to be printed and discarded, since otherwise Retina does not output until the program terminates.
18 bytes for a traditional decimal output. Each integer is printed in turn, and then for each integer all of the previous integers are printed again, so the final sequence is 1, 2, 1, 3, 2, 1, 4, 3 ...
{`^
_
*(M!&`_+
%`_
CASIO BASIC (CASIO fx-9750GIII), 24 bytes
1
Lbl A
For 1→X To Ans
X◢
Next
Ans+1
Goto A
you need to press enter after every number due to how CASIO BASIC works
Bash, 21 19 bytes
s()(seq $[++n];s);s
1
1
2
1
2
3
…
Run the 19B version on Try It Online
This defines a function s that runs seq NUMBER where NUMBER starts at 1 and increments with each run, then it runs itself recursively. After the definition, we run s.
For the cost of 5B to specify -s\ (separator is a space character), it can be adapted to a one answer per line solution at 24 bytes:
s()(seq -s\ $[++n];s);s
1
1 2
1 2 3
…
Thunno, \$ 9 \log_{256}(96) \approx \$ 7.41 bytes
[1+DR1+ZK
13 chars for a better format: Attempt This Online!
Explanation
[1+DR1+ZK # TOS is initially 0
[ # while True:
1+ # increment TOS
DR1+ # push range(1, TOS+1)
ZK # pop and print
Vyxal, 3 bytes
Þ∞K
Þ∞ɾ
Explanation
Þ∞ # Push an infinite list of positive integers: [1, 2, 3, 4, 5, ...]
K # Get the prefixes of this list [[1], [1, 2], [1, 2, 3], ...]
ɾ # Inclusive one-range of each: [[1], [1, 2], [1, 2, 3], ...]
Appleseed, 16 bytes
(q(_(map 1to(1to
Anonymous function that can be called with no arguments and returns an infinite nested list ((1) (1 2) (1 2 3) ...). Try it online!
Explanation
(q ; Anonymous function
(_ ; that takes any number of arguments:
(map 1to ; Inclusive range from 1 to N for each N in
(1to)))) ; numbers from 1 to infinity
Python, 76 bytes
def n():
c=2
while 1:
yield from range(1,c)
c+=1
for i in n():print(i)
Uses generators and yield from to chain infinite ranges. You can call n directly for a generator.
Vyxal, 5 bytes
{nɾṄ,
Try it Online! The 5 flag makes the online interpreter time out after 5 seconds.
Explanation:
{ # Open a(n infinite) while loop
n # Get the loop variable's value
ɾ # Push the range from 1 to n
Ṅ # Join by spaces (ɾ creates a list)
, # Print
Regenerate -a, 14 bytes
(${$1+1} !1 )+
The only choice for the regex to make here is how many times to repeat the (...)+ loop. The first iteration will always print 1 , because the first alternative can't match, as $1 hasn't been defined yet.
On subsequent iterations, ${$1+1} does math on $1, treating its contents as a number. It ignores the trailing space, and adds 1 to it. This then becomes the new value for $1, etc.
The ! short-circuiting alternation prevents the second alternative, i.e. 1 , from being taken once it becomes possible for the first alternative, ${$1+1} , to match.
Rust, 50 bytes
||for i in(1..).flat_map(|n|1..n){print!("{} ",i)}
I know there are a couple of rust answers already, but this one is deterministic and takes a different (and shorter) approach to the problem. explanation:
||for i in(1..).flat_map(|n|1..n){print!("{} ",i)} //anonymous function
(1..) //for evey n from 1..infinite
.flat_map(|n|1..n) //map to range from 1..n and flatten
for i in {print!("{} ",i)} //print with a trailing space
Batch, 127 bytes
@echo off
setlocal enabledelayedexpansion
set "s=1"
set k=1
for /L %%a in (0,0,0) do (echo !s! &set /a k=k+1 &set "s=!s! !k!")
Scratch 3.0, 13 20 blocks/121 70 bytes
As SB Syntax:
define(n)(i
say(i
((n)+<(i)=(n)>)((1)+((i)*<(i)<(n
This says each term in the sequence. A delay can be added so that the numbers don't rapidly fire.
I have never seen scratch so abused. You call the empty name function with empty parameters. My goodness. Whatever saves bytes!
-51 thanks to @att
Explained
The main idea behind this program is that each "run" of natural numbers is printed until the value being printed is equal to the highest number of that run.
The first two lines of the function are pretty straightforward...define a function with parameters n (the upper limit of the current run of numbers) and i (the current number for printing), then output the value of i.
Then, we get to the fun part - the function call. The expression n + (i = n) determines if we need to move onto the next n: if i hasn't reached the upper limit, the expression evaluates as n. Otherwise, the expression is n + 1, giving us the next upper limit.
The expression 1 + (i * (i < n)) determines the next value of i. To properly understand this, consider the two different results i < n can evaluate to: if i is equal to n (that is, we have reached the upper limit of the current run and we need to consequently restart at 1), this will result in (1 + (i * 0)), which will always equal 1. However, if i is less than n, the expression will equal (1 + (i * 1)) = (1 + i) , which just happens to be the next value to print. Because there is no checks to see if execution should be halted, this goes on forever.
sed in unary, 16 bytes
s/^/1\n1/p;h;G;D
Each unary natural is on its own line. Seems to increase logarithmically.
sed has two spaces: the default one is called the pattern space and is lost after processing the next of input; the other one is the hold space, which instead is retained throughout execution. Both start empty.
(sed cannot run without input, so this program is run with an empty line as input).
The idea is to have the largest number encountered so far on the first line, and then have the result of the previous iterations on the succeeding lines.
s/^/1\n1/ replaces the beginning (symbolised with ^, really just empty space) with 1 followed by a newline (\n) and another 1. The p flag then prints the pattern space. The second 1 inserted increases the maximum number by 1, which was on the first line before the substitution, and now is on the second line.
h replaces the hold space with the contents of the pattern space, after which G appends the hold space to the pattern space, joining them by a newline. This is our method to retain the previous natural numbers encountered.
D deletes the first line (which in our case is always 1 thanks to the substitution made with the s command) and the newline after it. This effectively returns the largest number encountered so far back to the first line. Then D causes the program to be run from the beginning with what remains of the pattern space because the first line was not empty. Because the s command will always make sure the first line is not empty, the initial 1\n effectively acts only for D to cause the program to loop indefinitely.
sed 4.2.2, 15 bytes
:;s/^/1/p;h;G;t
sed 4.2.2 allows empty labels, ridding the need for 1\n and D.
Java (OpenJDK 8), 76 chars
void f(){for(int i=0,j;++i>0;out.println())for(j=0;j++<i;out.print(j+" "));}
Output (unlimited):
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
. . .
convey, 17 15 bytes
-2 thanks to Jo King!
>1\/v
:+<.+}
11
Previous version that used a 0-stream and incremented its indices by 1. Jo's variation uses a 1-stream that adds itself to its indices, thus shortening the last row.
Starting with the top left 0, we push it to the left. \ will push its length 1 downward, it will get incremented +1 and then length + 1 new 0s will be let through. So we generate 0, 0 0, 0 0 0, …
Those list get then dumped in a sink ] while their indices \. get incremented +1 and written to the output }: 1, 1 2, 1 2 3, …
AWK, 33 bytes
An approach different from @Noodle9's, that luckly uses one less byte.
{for(;;a[++i])for(j in a)print j}
{
for(;;a[++i]) # by only stating the array[element], that element is created in the array.
# all not assigned variables starts at 0.
# at first, i++ would return 0, and increment 1 to i;
# but ++i increments 1 to i, and then return its new value.
for(j in a) # for every element existing in the array,
print j # prints the element j.
}
AWK, 37 bytes
Prints numbers in one line.
{for(;;a[++i])for(j in a)printf j FS}
AWK, 51 bytes
Prints numbers in a pyramid.
{for(;;a[++i])for(j in a)printf j+1 in a?j FS:j RS}
Arm Thumb (with libc calls), 34 bytes
Raw machine code
f7ff fffe is for libc calls which haven't been linked yet.
Needs to be loaded at an address that is not a multiple of 4, due to alignment requirements. Yes, it is counterintuitive, but it will make sense later.
2400 a707 3401 2501 0038 0029 f7ff fffe
3501 42a5 d9f8 200a f7ff fffe e7f2 7525
0020
Uncommented Assembly
.thumb
.globl main
.thumb_func
main:
movs r4, #0
adr r7, str
.Lloop1:
adds r4, #1
movs r5, #1
.Lloop2:
movs r0, r7
movs r1, r5
bl printf
adds r5, #1
cmp r5, r4
bls .Lloop2
.Lloop2_end:
movs r0, #'\n'
bl putchar
b .Lloop1
str:
.asciz "%u "
Explanation
Equivalent C code:
#include <stdio.h>
#include <stdint.h>
int main(void)
{
uint32_t N = 0;
for (;;) {
++N;
for (uint32_t num = 1; num <= N; num++) {
printf("%u ", num);
}
putchar('\n');
}
// Unreachable
}
Since we are never returning from main, I say, "to hell with calling convention" and just overwrite the callee-saved registers with our local variables. They won't know the difference. 😈
Specifically, I want r4 to be N (it is incremented before using), and r7 to be our printf string.
Unfortunately, we have an odd number of instructions, and adr can only load addresses that are 4 byte aligned, so we need to make main not be 4-byte aligned so the string is 4-byte aligned.
main:
movs r4, #0
adr r7, str
Begin printing the natural numbers. Increment N and start counting ℕ in r5.
.Lloop1:
adds r4, #1
movs r5, #1
printf("%u ", ℕ)
.Lloop2:
movs r0, r7
movs r1, r5
bl printf
Increment ℕ and loop while it is less than or equal to N.
adds r5, #1
cmp r5, r4
bls .Lloop2
After the second loop: putchar('\n')
.Lloop2_end:
movs r0, #'\n'
bl putchar
Jump back to the outer loop to increment N.
b .Lloop1
The printf string. This must be 4-byte aligned for adr, which we do with how we load main.
str:
.asciz "%u "
PowerShell Core, 14 bytes
for(){1..++$i}
Will output the numbers of the sequence separated by a new line.
Common Lisp, 56 bytes
(do((i 1(1+ i)))(())(dotimes(j i)(format t"~v^~a "j j)))
Nested loop solution using the do macro for the outer loop and the dotimes macro for the inner loop. dotimes starts with 0 so format includes a specifier that checks whether it's a 0.
Nim, 47 bytes
var i=1
while true:
for j in 1..i:echo j
i+=1
Try it online! The footer makes it finite so the output can be observed.
Note that Nim doesn't have bigints, so this works only in theory (in accordance with our rules).
Zsh, 29 .. 19 bytes
Solution by @AdamKatz: Try it Online!
for ((;++i;))seq $i
19 bytes, port from bash : s(){seq $[++n];s};s
25 bytes (per @AdamKatz) : for ((;++i;))echo {1..$i}
25 bytes : for ((;;i++))shuf -i 1-$i
26 bytes (per @AdamKatz) : for ((;;))echo {1..$[++i]}
29 bytes : for ((i=1;;))echo {1..$[i++]}
I tried to use /dev/random for an alternative but it was a mess!
Julia, 47 46 bytes
Thanks to @user recommended to change true to 1>0.
a=[1];while 1>0;println(a);push!(a,last(a)+1);end
output:
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
Python 3, 45 bytes
a=[1]
while 1:
print(a)
a+=[a[-1]+1]
jq, 24 bytes
range(range(infinite))+1
Try it online! (requires the -n flag)
JQ is a stream-based language: every expression can return multiple values and when expressions are combined together the second one is flat-mapped over everything returned by the first. This makes it very easy to express infinite sequences.
infinite is a filter that ignores its input and returns a single infinite floating-point value.
range(n) is a filter that ignores its input and returns every positive integer smaller than n.
+1 adds one to each value in the result.
By default if we run this program it will try to read from STDIN (because each filter needs to take an input, even if it is ignored). Therefore we pass the -n flag to tell the interpreter to pass a single null value as the input to the filter.
Java (JDK), 54 bytes
A b;{b=(s,i)->{System.out.print(s+=i+++s);b.B(s,i);};}
Usually in lambda functions, this website doesn't include the "interface name =" part, but my answer was a declaration statement without the initialization, so I decided to include it. I couldn't find a rule about it.
My older, wrongly counted, 47 byte solution: Try it online!
(forced) inputs: a String with any delimiter (" "), and 1, where Y is the class it's in, b is the name of the interface object, and B is the method in the interface being used.
Rust + rand crate, 43 bytes
||loop{print!("{} ",rand::random::<u32>())}
Uses the rand crate to output random numbers, meaning every number is printed infinitely many times.
Burlesque, 6 bytes
,r1)ro
Explanation:
, # Don't take implicit input from stdin
r1 # Range from 1 to infinity
) # Map each value to
ro # Range from 1 to value
Java (JDK), 61 bytes
v->{for(int i,j=2;;j++)for(i=0;++i<j;)System.out.println(i);}
Edit: Thanks @user for shaving off a few bytes and helping me learn something today! Big thanks to @KevinCruijssen for -2 bytes.
AutoHotkey, 36 bytes
Loop
Loop,%A_Index%
Send,%A_Index%`t
Output is via keyboard simulation so it will print in whatever the active window is.
Numbers are separated by tabs.
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Alternatively - and not in compliance with the challenge spec - if you prefer your numbers to be spoken rather than printed:
Loop
Loop,%A_Index%
ComObjCreate("SAPI.SpVoice").Speak(A_Index)
Befunge, 5 bytes
>1+?.
At each output, there is a 50% chance the current number will be printed and reset to 1, and a 50% chance that 2 will be printed and the current number will increase by some random odd number (following an exponential distribution). This can happen multiple times, so odd numbers can be outputted as well.
Every natural number has a nonzero probability of occurring, so it will eventually be printed infinitely many times.
Explanation
>1+?.
> # Go east.
1+ # Initialize a counter to 1.
? # Go in a random direction.
# If the instruction pointer goes west:
+ # Add the top two stack elements together.
# If there is a 2 on top, this adds it to the counter.
# If not, this does nothing.
1 # Create a new 1 on the top of the stack.
> # Go east.
1+ # Add 1 to get 2, which remains on top of the counter.
? # Repeat.
? # If the IP goes east:
. # Print and delete the top of the stack.
> # Go east.
1+ # Add 1.
# If there was a 2 that was printed and the counter remains, the 1 gets added to it.
# If the counter was printed instead, this creates a new 1.
? # Repeat.
? # If the IP goes north or south, it wraps around to the ? instruction and repeats.
Befunge-98, 14 bytes
]:.1-:0`j
]:+!
A determinstic solution, printing each range from 1 to n in descending order.
Explanation
] # Turn right (to the south) and go to the second line.
]:+!
] # Turn right again (to the west).
! # Take the logical NOT of the secondary counter (which is now 0) to get 1.
+ # Add the 1 to the main counter.
: # Duplicate the main counter to form a secondary counter.
] # Turn right (to the north) and go to the first line.
]:.1-:0`j
] # Turn right (to the east).
: # Duplicate the secondary counter.
. # Print and delete the duplicate.
1- # Subtract 1 from the secondary counter.
0` # Is the secondary counter greater than 0?
j # If so, jump over the ] instruction and repeat the first line.
] # If not, turn right (to the south) and go to the second line.
Raku, 18 bytes
.say for [\,] 1..*
[\,] 1..* generates the list of prefixes of the sequence of naturals. .say for just prints them.
Haskell, 17 bytes
[[1..x]|x<-[1..]]
Since the challenge seems to allow non-flat output, we can simply generate a list of the lists [1],[1,2],[1,2,3,],..., as suggested by @AZTECCO.
Haskell, 19 bytes
l=1:do x<-l;[x+1,1]
A recursively-defined infinite flat list with the ABACABA sequence 1,2,1,3,1,2,1,4,... (A001511).
A same-length variant:
l=(:[1]).succ=<<0:l
20 bytes
l=do x<-[1..];[1..x]
Counting up 1,1,2,1,2,3,1,2,3,4,..., but as a flat list.
R, 21 bytes
(also near-simultaneously identified by Robin Ryder)
while(T<-T+1)cat(T:0)
Similar to the example sequence, but each sub-series is reversed, and the initial value in each subseries is represented with an initial zero (so, 03 for 3, for instance).
If you don't like the initial zeros, then look at the previous version using show (below), or at Giuseppe's answer.
R, 23 22 bytes
Edit: -1 byte thanks to Robin Ryder
while(T<-T+1)show(1:T)
Outputs the sequence used in the example, plus an additional infinite number of copies of the number 1.
Each number is separated by either a space " " , a newline plus bracket, "\n[", or a bracket plus space "[ ".
2-bytes golfier (at time of posting, at least...) than the other two R answers...
R, 25 21 bytes
repeat T=print(T:0+1)
Prints 2..1, 3..1, 4..1 and so forth.
Thanks to Robin Ryder for -4 bytes.
This works because print invisibly returns its first argument.
Icon, 46 bytes
procedure f()
i:=0;|1&write(1to(i+:=1))&\z
end
Of course procedure ... end block makes it very verbose.
Too bad seq() doesn't work with bigints - otherwise I could've saved some bytes with
procedure f()
|1&write(1to seq())&\z
end
R, 26 25 24 bytes
-1 byte thanks to Dominic van Essen
repeat cat(rpois(9,9)+1)
Outputs a random infinite sequence of integers, drawn from the \$Poisson(9)\$ distribution (+1 to avoid outputting any 0s). They are output in batches of 9 at a time, for more "efficiency". Any positive value of the mean would work; using a mean of 9 maximizes the variance for 1-character numbers.
All numbers appear infinitely often in the sense that for any integer \$k\$, the expected number of occurences of \$k\$ in the first \$n\$ realizations goes to \$\infty\$ as \$n\to\infty\$:
$$E\left[\sum_{i=1}^n\mathbb{I}_{X_i=k}\right]\xrightarrow[n\to\infty]{}\infty.$$
The calls to cat mean that there integers within one batch of 9 are separated by spaces, but there is no separator between batches. The vast majority of 3- and 4-digit numbers in the output are due to this artefact, but there is a theoretical guarantee that such numbers (and larger numbers) will be output eventually, at least if we assume that the underlying random number generator is perfect.
For a larger variance, we can follow Giuseppe's suggestion for the same byte count:
repeat cat(1%/%runif(9))
This induces more 1s and more large numbers (including some very large numbers thanks to the cat artefact). Again, number of occurrences of any integer goes to infinity when the size of the output goes to infinity.
Two other R answers come out shorter, using deterministic methods: Giuseppe's and Dominic van Essen's
Pyth, 4 bytes
f!pS
Explanation
f!pS
: lambda T:
S : range(1, T)
p : print and return the range
! : logical negate the range
f : Find first natural number input to function that returns a truthy value
Wolfram Language (Mathematica), 31 bytes
Print@Floor[Sec@n^2]~Do~{n,∞}
Not quite as short as the other Mathematica answer, but implements a different and more mathematically interesting sequence, namely the integer part of \$\sec^2n\$; the fact that this includes every natural number infinitely often follows from the fact that the integers are uniformly distributed modulo \$\pi\$.
Python 2, 31 bytes
R=1,
while 1:print R;R+=len(R),
Thanks to @Danis for saving a byte here over R+=R[-1]+1,. This
Prints:
(1,)
(1, 1)
(1, 1, 2)
(1, 1, 2, 3)
(1, 1, 2, 3, 4)
(1, 1, 2, 3, 4, 5)
...
Accumulates a list of number from 1 to n (except 1 appears twice) each time appending the last element plus one.
32 bytes
R=[1]
for x in R:print R;R+=x+1,
Python 2, 30 bytes (conjectured)
n=2
while 1:print~-2**n%n;n+=1
The sequence of \$2^n \bmod n\$ (A015910) is conjectured to take on all values \$k \geq 0\$ except \$k=1\$. I don't know if it's also conjectured that each value appears infinitely many times, but it seems consistent with known solutions for specific values.
We instead compute \$(2^n-1) \bmod n\$, which makes \$0\$ rather than \$1\$ be the only missing value (if the conjecture holds).
Looking at the output, you might think that \$2\$ is never output, but it in fact does appear first for \$n=4700063497\$ and for progressively higher values in A050259.
Python 2, 33 bytes
R=[1]
for x in R:print x;R+=x+1,1
This is longer, but it's pretty nifty, printing the ABACABA sequence.
C (gcc), 52 49 44 bytes
Saved 5 bytes thanks to AZTECCO!!!
f(i,j){for(j=1;printf("%d ",j--);)j=j?:++i;}
JavaScript (Browser), 40 bytes
f=(x=1)=>setInterval(_=>alert(x,f(x+1)))
Not very competitive answer :(
JavaScript (V8), 26 bytes
for(a=b='';;)write(a+=--b)
Character - used as a separator and the output starts with it, so I'm not really sure if this is acceptable.
Factor, 32 bytes
1 [ dup bit-count . 1 + t ] loop
Loops over the positive integers and prints their bit count (the number of 1 bits, a.k.a. popcount) forever. Outputting nth term would be simply 9-bytes bit-count. (I checked that the function works with bigints.)
Uses the same logic as Neil's Charcoal answer that there are infinitely many numbers whose digit sum equals n, except that this one uses bits instead. More precisely, for any positive integer n, \$2^m(2^n-1)\$ for any non-negative integer m has exactly n bits on, so the sequence contains infinitely many n's for any n.
JavaScript (V8), 34 bytes
Saved 2 bytes thanks to @tsh
for(n=k=0;;)print(n=n<k?n+1:++k/k)
Returning the n-th term would be 31 bytes:
n=>(m=(8*n+1)**.5-1>>1)*~m/2-~n
Stax, 5 bytes
VImRJ
Explanation
VImRJ
VIm map 1..infinity to
R range 1..i
J join with spaces
m print each iteration
PHP, 30 bytes
<?for(;;)echo--$j?:$j=++$i,~_;
The numbers are separated by a no-break space (U+00A0).
Charcoal, 8 bytes
W¹«I⊕ⅉD⸿
Try it online! Link is to verbose version of code. Works by repeatedly printing the next number to the canvas and then dumping the entire canvas.
2 bytes for a version that prints the \$ n \$th term of a sequence:
IΣ
Try it online! Explanation: Simply prints the digital sum of the input. Given any natural number \$ n \$, all the values of the form \$ \frac { 10 ^ n - 1 } 9 10 ^ m \$ have a digital sum of \$ n \$ for every \$ m \$, thus each natural number appears infinitely often.
APL (Dyalog Unicode), 12 11 bytes (SBCS)
Saved 1 byte thanks to @ovs
{∇1+⍴⎕←⍳⍵}1
This one also uses the sequence from the question.
Octave, 29 28 bytes
do disp(fix(1/rand)) until 0
This outputs a sequence \$(x_k)\$ of independent, identically distributed random natural numbers. Each value \$x_k\$ is obtained as \$1/r\$ rounded towards zero, where \$r\$ has a uniform distribution on the interval \$(0,1)\$.
For a given index \$k\$, and for any \$n \in \mathbb N\$, there is a nonzero probability that \$x_k=n\$ (ignoring floating-point inaccuracies). Therefore, with probability \$1\$ every \$n\$ appears infinitely often in the sequence \$(x_k)\$.
J, 13 bytes
$:@,~[echo@#\
Outputs 1, 1 2, 1 2 3 4, 1 2 3 4 5 6 7 8, etc, with every number on its own line.
echo@#\Output the prefix lengths of the current list, ie,1..nwhere n is the current list length. This is done as a side effect.$:@,~Append the list to itself,~and call the function recursively$:@.
Python 2, 24 33 bytes
Added 9 bytes to fix an error kindly pointed out by caird coinheringaahing.
n=1
while 1:n+=1;print range(1,n)
Jelly, 4 bytes
‘RṄß
I think this outputs all numbers an infinite number of times, but because it's a different output format, I'm not 100% sure
How it works
‘RṄß - Main link. Left argument is initially n = 0
‘ - Increment
R - Range
Ṅ - Print
ß - Recursively run the main link
For n = 0, ‘RṄ outputs [1]. We then recurse, using n = [1]. ‘RṄ then outputs [[1, 2]], and we recurse again, using n = [[1, 2]], which outputs [[[1, 2], [1, 2, 3]]] etc.
Husk, 2 bytes
ḣN
First Husk answer! Also uses the sequence in the question
How it works
ḣN - Main program
N - The infinite list [1, 2, 3, ...]
ḣ - Prefixes; [[1], [1, 2], [1, 2, 3], ...]
05AB1E, 2 bytes
∞L
Try it online! The footer formats the output like the example from the post.
∞ pushes a list of all natural numbers, L takes the range [1 .. n] for each number.
Scala, 23 bytes
Stream from 1 map(1 to)
An infinite Stream of IntRanges. Uses the sequence from the question.



