| Bytes | Lang | Time | Link |
|---|---|---|---|
| 023 | Tcl | 170203T175733Z | sergiol |
| 013 | Raku Perl 6 rakudo | 241213T160222Z | xrs |
| 108 | BrainChild | 241128T044438Z | ATaco |
| 006 | punchcode | 241127T225553Z | madeforl |
| 039 | Rust | 240813T002412Z | user9403 |
| 031 | JavaScript Node.js | 240813T212004Z | Andrew B |
| 029 | Bash | 240813T141750Z | wobtax |
| 111 | Setanta | 240813T032403Z | bb94 |
| 029 | Octave | 240416T121334Z | cnln |
| 083 | Acc!! | 240415T105545Z | Mukundan |
| 021 | Swift | 230715T132857Z | macOSist |
| 049 | Rust | 240213T065553Z | Joonas |
| 030 | Dart | 240211T164751Z | enzo |
| 085 | C++ gcc + libgmp | 240210T044851Z | Digital |
| 090 | c + GMP library | 151114T214749Z | Digital |
| 003 | Vyxal 3 | 231201T233551Z | Fmbalbue |
| nan | { | 230728T174544Z | Dadsdy |
| 066 | ForWhile | 230715T122526Z | bsoelch |
| 045 | Racket – | 230711T204826Z | Ed The & |
| 047 | Linux X86_64 | 230605T221023Z | kwzuu |
| 064 | C | 230617T080901Z | kwzuu |
| 021 | Arturo | 230614T214824Z | chunes |
| nan | 230607T034200Z | Dadsdy | |
| 072 | C++ gcc | 230602T192857Z | Wallace |
| 030 | Rockstar | 230529T222534Z | Shaggy |
| 003 | Desmoslang Assembly | 230529T141632Z | Dadsdy |
| 005 | Rattle | 210727T225035Z | d01 |
| 041 | Rust | 220324T082927Z | Sapherey |
| 046 | Fortran GFortran | 230103T205606Z | roblogic |
| 007 | Unix coreutils jot | 230103T204642Z | roblogic |
| 001 | GNU sed 4.2.2 rn /dev/random | 230102T183019Z | Ginger |
| 010 | Seed | 221226T042806Z | autumn |
| 022 | makina | 221005T151701Z | Unit Tes |
| 013 | Knight | 220807T023616Z | Aiden Ch |
| 019 | Factor + lists.lazy | 220517T163516Z | chunes |
| 045 | A0A0 | 220517T134947Z | stefvans |
| 026 | Python 3 | 220324T172204Z | Sapherey |
| 069 | Rust | 200817T210833Z | Aiden4 |
| 014 | Charcoal | 220122T000453Z | Fmbalbue |
| 048 | KonamiCode | 211112T140357Z | Ginger |
| 027 | JavaScript V8 | 210727T215407Z | user9403 |
| 008 | convey | 211111T011047Z | Jo King |
| 009 | ErrLess | 211110T150438Z | Ruan |
| 007 | Add++ | 211109T152928Z | Fmbalbue |
| 003 | Vyxal | 210725T091526Z | emanresu |
| 004 | ABC | 210424T074147Z | wasif |
| 034 | VBScript | 210408T100735Z | wasif |
| 012 | Dash | 210408T085301Z | user1004 |
| 021 | JavaScript ES6 | 190207T013430Z | Yair Ran |
| 057 | Scratch 3.0 | 210316T190057Z | Bo_Tie |
| 003 | 05AB1E | 191226T153353Z | Sagittar |
| 003 | Stax | 210226T173222Z | Razetime |
| 003 | v³ | 210226T155500Z | Bo_Tie |
| 040 | Elixir | 210226T142224Z | Kirill L |
| 004 | Ace | 180108T235330Z | qqq |
| 001 | 05AB1E | 201129T012518Z | Makonede |
| 004 | Pushy | 161127T212858Z | FlipTack |
| 003 | Jelly | 170615T154001Z | Christia |
| 1511 | Billiards | 170211T021609Z | hyperneu |
| 015 | Braingolf | 170525T123949Z | Mayube |
| 025 | Bash | 200821T043558Z | Quelklef |
| 004 | Arn | 200821T023302Z | ZippyMag |
| 007 | CJam | 200712T173746Z | Ethan Ch |
| 063 | Brainetry w 0 | 200712T144350Z | RGS |
| 024 | Python 3 | 200712T143757Z | Surculos |
| 004 | DIVCON | 200712T134227Z | user9206 |
| 512 | Microsoft PowerPoint 33 Slides | 200114T161732Z | General |
| 053 | Python 3 | 200104T144420Z | user8505 |
| 097 | C# .NET 4.0 | 151115T090753Z | Kazarp |
| 003 | W | 191214T060910Z | user8505 |
| 033 | tinylisp | 191206T181341Z | user4180 |
| 1816 | Wolfram Language Mathematica | 190713T222234Z | Roman |
| 026 | Tamsin | 190323T045211Z | Esolangi |
| 004 | MathGolf | 190306T140617Z | Kevin Cr |
| 021 | Haskell | 151114T151206Z | Bergi |
| 446 | Runic Enchantments | 190206T011120Z | Draco18s |
| 029 | Deoxyribose | 190201T190059Z | georgewa |
| 019 | Alchemist | 190201T031216Z | Jo King |
| 2214 | Chip | 170202T194433Z | Phlarx |
| 004 | Brachylog | 180821T135831Z | Kroppeb |
| 006 | Pip | 180820T193536Z | DLosc |
| 014 | Yabasic | 180222T201645Z | Taylor R |
| 015 | Flobnar | 180814T041943Z | Jo King |
| 017 | Momema | 180813T222947Z | Esolangi |
| 006 | Noether | 180731T143929Z | Beta Dec |
| 022 | Foam | 180707T063711Z | Esolangi |
| 076 | Visual Basic .NET .NET Core | 180222T210332Z | Taylor R |
| 004 | Stax | 180222T043733Z | Weijun Z |
| 005 | Wumpus | 180210T202314Z | Martin E |
| 030 | Julia 0.6 | 180126T231126Z | gggg |
| 034 | tinylisp | 180126T205811Z | DLosc |
| 006 | Pyt | 180126T203420Z | qqq |
| 027 | AutoHotkey | 180123T084952Z | user7277 |
| 013 | Retina | 180118T140611Z | Martin E |
| 031 | brainfuck | 180108T055211Z | Jo King |
| 006 | Pyt | 180108T014600Z | mudkip20 |
| nan | JavaScript ES6 | 171213T163328Z | l4m2 |
| 006 | Alumin | 171213T151342Z | Riker |
| 054 | ALGOL 68 Genie | 171212T192906Z | KSmarts |
| 005 | Aceto | 171116T062233Z | qqq |
| 117 | TrumpScript | 171124T073526Z | Luca H |
| 004 | Implicit on TIO | 170908T024019Z | MD XF |
| 015 | ><> | 171118T003315Z | Bolce Bu |
| 152 | TIBASIC Z80 | 171018T014236Z | Jakob |
| 006 | Anyfix | 170617T015326Z | hyperneu |
| 009 | Triangular | 170615T152433Z | MD XF |
| 009 | APL Dyalog | 171114T172321Z | Erik the |
| 001 | Husk | 171114T170646Z | Erik the |
| 1055 | Brainfuck | 171024T154943Z | Kamila S |
| 146 | Swift 4 | 171024T134627Z | xoudini |
| 069 | JavaScript ES6 | 160425T150941Z | Qwertiy |
| 006 | RProgN 2 | 171009T043518Z | ATaco |
| 011 | Cubically | 170805T174741Z | MD XF |
| 027 | Casio Basic | 170722T142746Z | numberma |
| 031 | 8th | 170722T135121Z | Chaos Ma |
| 001 | cQuents | 170719T124201Z | Stephen |
| 040 | Whitespace | 170527T144408Z | Ephphath |
| 013 | Check | 170603T040111Z | Esolangi |
| 010 | Braingolf | 170603T031604Z | totallyh |
| 025 | Groovy | 170527T150956Z | Ephphath |
| 010 | APL Dyalog APL | 160229T132433Z | Adá |
| 157 | ArnoldC | 170525T122246Z | TheLetha |
| 010 | Fourier | 170423T111628Z | Beta Dec |
| 032 | Swift | 170423T110939Z | Mr. Xcod |
| 006 | Alice | 170423T105503Z | Sp3000 |
| 008 | QBIC | 170331T181544Z | steenber |
| 103 | VBA | 170329T171638Z | Engineer |
| 034 | REXX | 170330T173006Z | idrougge |
| 012 | stacked | 170228T035027Z | Conor O& |
| 087 | SmileBASIC | 170211T025757Z | 12Me21 |
| 003 | Pyke | 160425T173050Z | Blue |
| 013 | Perl 6 | 160424T105545Z | Ven |
| 064 | PHP | 161206T142001Z | Titus |
| 004 | Befunge | 161004T143600Z | Hactar |
| 006 | Brachylog | 160202T153401Z | Fatalize |
| 002 | Sesos | 160722T103309Z | Leaky Nu |
| 042 | Oracle SQL | 160621T132923Z | Giacomo |
| 004 | 05AB1E | 160610T140701Z | Emigna |
| 027 | Lua | 160523T124622Z | Katenkyo |
| 014 | UGL | 160423T233630Z | Leaky Nu |
| 006 | Tellurium | 160520T133243Z | m654 |
| 063 | Node.js + Big.js | 160511T024650Z | Conor O& |
| 073 | Retina | 160204T230632Z | mbomb007 |
| 067 | JavaScript ES6 | 151114T160604Z | user8165 |
| 072 | C++ | 160425T140314Z | Michelfr |
| 034 | AutoHotKey | 160425T142714Z | Michelfr |
| 004 | Fuzzy Octo Guacamole | 160425T141701Z | Riker |
| 020 | Retina | 160423T233230Z | Leaky Nu |
| 019 | Perl | 160423T232422Z | Ton Hosp |
| 076 | Molecule | 160423T173657Z | user4701 |
| 021 | PRINDEAL | 160423T135952Z | The Fift |
| 006 | Pylongolf2 | 160401T050538Z | user4701 |
| 003 | Jelly | 160229T172917Z | Sp3000 |
| 083 | C# | 160229T195418Z | EnragedT |
| 061 | Aubergine | 151124T085946Z | quintopi |
| 030 | UberGenes | 151124T072007Z | quintopi |
| 035 | ForceLang | 160229T032947Z | SuperJed |
| 025 | Hoon | 160229T005500Z | RenderSe |
| 057 | D | 160228T154803Z | cat |
| 027 | WhoScript | 151230T034143Z | MCS-Kaij |
| 036 | F# | 160202T210600Z | Roujo |
| 012 | dc | 151114T160211Z | daniero |
| 046 | Bash | 160202T145852Z | Ogaday |
| 016 | GNU coreutils | 151130T183948Z | Toby Spe |
| 009 | Y | 160218T190459Z | Conor O& |
| 004 | Pyth | 160109T061334Z | benstopi |
| 035 | Prolog SWI | 151116T130546Z | Emigna |
| nan | BotEngine | 151114T171515Z | SuperJed |
| 004 | Seriously | 151114T171022Z | user4594 |
| 095 | Matlab | 151118T143250Z | Abr001am |
| 536 | Turing Machine Simulator | 151230T081347Z | KoreanwG |
| 071 | Forth | 151229T181838Z | cat |
| 017 | Mouse2002 | 151229T161233Z | cat |
| 002 | Samau | 151229T032550Z | alephalp |
| 022 | Mathematica | 151117T221625Z | LegionMa |
| 010 | bc | 151114T211548Z | Digital |
| 036 | GNU sed | 151130T182121Z | Toby Spe |
| 044 | Brainfuck | 151130T152234Z | Mario Ca |
| 065 | awk | 151124T182723Z | Cabbie40 |
| nan | 151122T203029Z | Adam Dal | |
| 010 | JacobFck | 151119T163554Z | Jacob Mi |
| 052 | R | 151117T185932Z | SnoringF |
| 025 | Python 3 | 151114T124736Z | flawr |
| 017 | Clojure | 151117T055044Z | dmh |
| 358 | Marbelous | 151115T061542Z | Sparr |
| 023 | PARI/GP | 151114T235302Z | primo |
| 014 | PowerShell | 151116T165309Z | Chad Bax |
| 030 | Common Lisp | 151116T214139Z | Joshua T |
| 029 | Powershell | 151114T204912Z | Booga Ro |
| 024 | Python 2 | 151116T202634Z | mbomb007 |
| 4632 | Marbelous | 151114T185421Z | TheDocto |
| 083 | sed | 151115T002001Z | matz |
| nan | VB.NET | 151115T150223Z | Jens |
| 023 | Perl | 151114T223938Z | Kenney |
| nan | Go | 151116T105741Z | Kristoff |
| 009 | Burlesque | 151114T130002Z | mroman |
| 077 | C + gcc extensions | 151116T062504Z | xsot |
| 007 | O | 151116T025307Z | jado |
| 034 | 8086 machine code + DOS | 151115T215134Z | anatolyg |
| 012 | Ruby | 151114T154955Z | daniero |
| 019 | Intel 8086+ Assembly | 151115T015651Z | Kenney |
| 013 | Perl 6 | 151115T174427Z | Brad Gil |
| 104 | C++ | 151115T163851Z | lynn |
| 095 | C | 151115T161706Z | lynn |
| 078 | Ceylon on JVM | 151114T215252Z | Paŭlo Eb |
| 035 | Scala | 151114T211801Z | TWiStErR |
| 007 | Hexagony | 151114T140428Z | Martin E |
| 035 | Julia | 151115T064151Z | Alex A. |
| 138 | C++ | 151115T020157Z | felixphe |
| 933 | Win32 x86 Machine Code PE32 Executable | 151115T004608Z | user4264 |
| 040 | Racket | 151115T001705Z | Alexis K |
| 009 | GolfScript | 151114T234730Z | primo |
| 031 | PHP | 151114T233858Z | primo |
| 004 | Minkolang | 151114T213335Z | El'e |
| 065 | Acc! | 151114T211518Z | The Fift |
| 006 | Foo | 151114T211805Z | Zach Gat |
| 102 | Kotlin | 151114T205623Z | TWiStErR |
| 071 | Processing | 151114T154704Z | geokavel |
| 123 | Java | 151114T143546Z | SuperJed |
| 089 | C | 151114T170257Z | Helco |
| 007 | Rotor | 151114T162112Z | a spaghe |
| 014 | Python 2 VM Opcodes | 151114T150537Z | Blue |
| 004 | Befunge | 151114T160038Z | PurkkaKo |
| nan | 151114T125300Z | flawr | |
| 008 | ><> | 151114T133614Z | randomra |
| 093 | C | 151114T150501Z | edc65 |
| 007 | CJam | 151114T144551Z | GamrCorp |
| 053 | C 64bit architecture only | 151114T141324Z | feersum |
| 011 | MarioLANG | 151114T134451Z | alephalp |
| 003 | Gol><> | 151114T132244Z | randomra |
| 022 | Mathematica | 151114T131949Z | alephalp |
| 005 | Labyrinth | 151114T130143Z | Sp3000 |
| 004 | Pyth | 151114T124725Z | Jakube |
Raku (Perl 6) (rakudo), 13 bytes
.say for 0..*
AWK, 21 bytes
END{for(;;)print i++}
Both work with 2^128 and beyond without issue, although AWK is significantly quicker.
BrainChild, 108 bytes
include *;while(int a~-1|int b~-1|int c~-1|int d~-1){if(!++a)if(!++b)if(!++c)d++printf("$0$1$2$3 ",d,c,b,a)}
Brainchild doesn't support 128 bit integers, so this solution just tracks 4 separate 32 bit integers and ticks the next one every time the last one rolls over. This version of Brainchild neglected to implement binary not, so xor -1 is used instead.
punchcode, 6 bytes
[RS][ESC][VT][GS][CR][LF]
uncompiled:
-START |
---OOOO-|
---OO-OO|
----O-OO|
---OOO-O|
----OO-O|
Bash, 29 bytes
while echo $((++n));do :;done
Explanation: repeatedly increment n (from 0), then print it. This always succeeds, so the loop condition is always true.
Note that this has side-effects. If you cancel the program, n will still be set in the current shell, so it will continue where it left off. You can reset by running unset n first.
Setanta, 111 bytes
t:=[0]*40nuair-a 1{i:=39nuair-a!t[i]{i-=1t[i]=(t[i]+1)%10}i=0nuair-a!t[i] i+=1scriobh(nasc@(cuid@t(i,39))(""))}
Explanation
Setanta doesn’t have a number type that can handle numbers as large as required, so I use an array of digits.
t:=[0]*40nuair-a 1{i:=39nuair-a!t[i]{i-=1t[i]=(t[i]+1)%10}i=0nuair-a!t[i] i+=1scriobh(nasc@(cuid@t(i,39))(""))}
t:=[0]*40 >-- Array of digits, with a sentinel value at the end
nuair-a 1{ } >-- Loop the following infinitely:
i:=39 >-- Index into t for current digit being updated
nuair-a!t[i]{ } >-- While t[i] != 0...
i-=1 >-- Decrement i
t[i]=(t[i]+1)%10 >-- Increment the current digit; will loop again if it becomes 0
i=0nuair-a!t[i] i+=1 >-- Find the index of the first nonzero digit
cuid@t(i,39) >-- Get the sublist from that index (excluding the sentinel value)...
nasc@( )("") >-- Join the elements...
scriobh( ) >-- And print the resulting string
💎
Created with the help of Luminespire.
Octave, 29 bytes
j=0;while 1
j=vpa(j,39)+1
end
This makes use of the vpa function for variable precision numbers. I set the precision at 39 based on the minimum value of \$2^{128}\$ from the question, but it can be increased arbitrarily.
Acc!!, 91 83 bytes
-8 bytes thanks to @DLosc
Count i while 1 {
_+i/10^_
Count j while _-j {
Write i/10^(_-j-1)%10+48
}
Write 9
}
Note this outputs a leading tab, can be avoided at the cost of 8 bytes.
Unlike the other Acc!! answer this one outputs in decimal instead of unary.
Swift, 24 21 bytes
(1...).map{print($0)}
Pretty self-explanatory, I feel. Numbers are separated by newlines.
Dart, 30 bytes
main(i){for(i=0;;print(i++));}
It's equivalent to the following Dart code:
dynamic main(dynamic i) {
for (i = 0;; print(i++));
}
i starts as a List<String>, equivalent to Java's args. But omitting its type makes it dynamic, making it assignable to any type. Inside the loop, it changes its type to an integer and sets it to zero.
C++ (gcc) + libgmp, 85 bytes
I'm currently polishing my C++ skills. Despite the clunky boilerplate, this turned out to be surprisingly idiomatic and readable.
#include<gmpxx.h>
#include<iostream>
mpz_class i;main(){while(std::cout<<++i<<'\n');}
c + GMP library, 90
Score includes +4 for passing -lgmp to the compiler. You'll need GMP installed to build and run this.
Here's how we do arbitrary precision in c:
#include<gmp.h>
main(){mpz_t i;for(mpz_init(i);mpz_add_ui(i,i,1),gmp_printf("%Zd\n",i););}
Compile with:
cc forever.c -o forever -lgmp
Vyxal 3, 3 bytes
{m,
-1 byte thanks to @lyxal
Explanation:
{m,
{ # Infinite loop (For [1..infinity])
m # context variable
, # Print with newline
💎
Created with the help of Luminespire.
{,}, 31 Chars or \$31\log_{256}(4)\approx\$ 7.75 Bytes
((()()()),(),((()()()),())())()
Log base 4 because there are (, {, commas, and closing brackets (which are unambiguous because the code is balanced)
ForWhile, 66 bytes
(!;$1-:){}9+:66(.:@;66-$1-:).9@1+:0;(.;10%48+'1+3,10/';)+(.#)9#$66
infinitly prints numbers in decimal separated by tabs.
In ForWhile every loop will exit after a finite number of iterations, and recursion is limited to a fixed depth (3), this means that every finite ForWhile program will terminate after a finite number of steps.
The only way to circumvent this is to write an "infinite" program by continuously generating more source-code at runtime.
The above program repeatedly copies its source code to a location right of the instruction pointer and the deletes the old source code (to prevent memory overflow).
Explanation
\ ignored in first iteration
(!;$1-:)
\ push current instruction pointer, offset it to point at the start of the current code-section
{}9+
\ copy the code to the address immediately after the current source-code
:66(.:@;66-$1-:).
\ load the value at address 9 and increment it
9@1+
\ print the integer converted to a decimal string
:0;(.;10%48+'1+3,10/';)+(.#)
\ print a tab and store the new value of the integer at address 9
9#$
\ push the length of the code
66
\ clear the previous code-section
(!;$1-:)
...
Shorter but less interesting solution (20 bytes)
2 129`:(;'-(.48#)9#)
prints the first 2129-1 numbers in unary separated by tabs.
Racket – 45 bytes
#!racket
(for([n(in-naturals)])(displayln n))
Explanation
Racket provides us with a neat little function called in-naturals that receives an optional argument which tells it where to begin. Since it is a stream (generator, in other languages), we can use it with Racket's for loop to display each number followed by a newline.
Documentation for in-naturals also says the following:
An
in-naturalsapplication can provide better performance for integer iteration when it appears directly in aforclause.
Which I assume means that the loop will be more faster to evaluate?
#lang racket
(for ([n (in-naturals)])
(displayln n))
Another cool thing about for is that it has a keyward argument called #:when that will only run the code in the loop if the condition is met:
#lang racket
; Code to print all numbers divisible by 31:
(for ([n (in-naturals)] #:when (zero? (modulo n 31)))
(displayln n))
Compilation on a machine
- Once Racket is set up, store this code as a file with the extension
.rkt. - Open a terminal of your choice.
- Check if Racket is in your path via
racket -v, if so, you can either:- Run the code directly via
racket filename.rkt(replacefilename.rktwith your file. - Compile the code to an executable using
raco exe filename.rkt. Once compiled, you'll have an executable in the current directory alongside the source file.
- Run the code directly via
Documentation
Linux X86_64, 55 54 47 bytes
newer version actually completes the challenge, using 136-bit integers :)
another improvement was suggested by ceilingcat; using pushq and popq instead of mov to set registers
register uses:
%rax: syscall number (1), %ah is always zero
%rdx: byte count (=18)
%rcx: clobbered by syscall
%bl: highest 8 bits of number
%rsp: pointer to top of string at the start of program, becomes middle 64 bits of number
%rbp: lowest 64 bits of number
%rsi: pointer to bottom of output string
%rdi: file descriptor (1)
0000000000000000 <_start>:
0: 6a 01 push $0x1
2: 5f pop %rdi
3: 6a 12 push $0x12
5: 5a pop %rdx
6: 6a 0a push $0xa
8: 48 89 e6 mov %rsp,%rsi
b: 48 83 ee 09 sub $0x9,%rsi
f: 31 db xor %ebx,%ebx
11: 31 ed xor %ebp,%ebp
13: 31 e4 xor %esp,%esp
0000000000000015 <loop>:
15: 88 1e mov %bl,(%rsi)
17: 48 0f 38 f1 66 01 movbe %rsp,0x1(%rsi)
1d: 48 0f 38 f1 6e 09 movbe %rbp,0x9(%rsi)
23: 89 f8 mov %edi,%eax
25: 0f 05 syscall
27: 48 01 fd add %rdi,%rbp
2a: 48 11 dc adc %rbx,%rsp
2d: 10 e3 adc %ah,%bl
2f: eb e4 jmp 15 <loop>
```
C, 64 bytes
s[9];i(int*s){while(!++*s++);}main(){for(;;)i(s)+write(1,s,36);}
There is no newline at the end of the file.
This prints out 35-byte little-endian integers, separated by null bytes (up until it hits 2^(25*8) at which point it breaks, but we don't talk about that :^)
It still works on my machine if s[9] is replaced with s[], which reduces it to 63 bytes. This is undefined behaviour so I didn't do it.
Run with gcc -o count count.c && ./count | hexdump -e '36/1 " %02x" "\n"' to nicely format the output.
C++ (gcc), 72 bytes
#include <iostream>
int main(){int i=1;while(1){std::cout<<i<<" ";i++;}}
Desmoslang Assembly, 3 Bytes
1O+
Explanation: Command gets 1 added to it, so it is 1. That is outputted, a plus is added, and it gos to the start because that is the default to value.
Fortran (GFortran), 46 bytes
integer(kind=16)::i
print*,(i,i=1,huge(i))
end
Theoretically it will iterate up to huge(i)==2^127. Need to import a library like fmlib to go higher.
GNU sed 4.2.2 -rn (/dev/random), 3 1 byte
=
Yup, that's it.
For this program to work correctly, it must be run on an infinite-length file that can output a newline byte; /dev/random works well for this. Run with sed -rn '=' /dev/random.
Knight, 15 13 bytes
Thanks @Steffan for -2 bytes
;=a 0W1O=a+1a
I have no idea what I'm doing but if it works then it works lol.
A0A0, 45 bytes
A0A0
A0C3G1G1A0
A0V1O0P9S1A0
A0A1G-3G-3A0
G-3
Prints 1 up to infinity, delimited by tabs. This uses a basic infinite loop construct, which executes the following infinitely:
V1 O0 P9 S1
V1 ; Operand, initialized with 1
O0 ; Outputs the operand as a number
P9 ; Prints a tab (ascii code 9)
S1 ; Increments the operand by 1
Edit: switched to tabs as a delimiter, since this saves 1 byte
Rust, 99 69 bytes
fn main(){for i in 0..=!0u128{print!("{i}
")}print!("{}6",!0u128/10)}
Try it on the Rust Playground!
45 bytes if it weren't for that darn inclusive. Also, be warned, the size of the output may cause the rust playground to crash.
Edit: saved 30 bytes with some help from @The Fifth Marshal, and it now prints out 2^128-1
Charcoal, 16 14 bytes
≔¹ξW¹«PIξ≦⊕ξR⁰
Try it online! Link is to verbose version of code.
-2 bytes thanks to Neil in the chat
I think the The output with trailing separator is valid.
Explanation:
≔¹ξ
Assign 1 to X
W¹«
Start Infinite Loop
PIξ
Print X, In decimal to avoid memory error
≦⊕ξ
Increment X
R⁰
Refresh
KonamiCode, 48 bytes
v(>)>(^)v(^^^>^^)>(>)L(>)<<<v((>))>(^)<<>(>)B(>)
This is actually quite similar to the 0-100 program, just without the comparison buffer being set.
JavaScript (V8), 37 27 bytes
for(i=1;1;)console.log(i++)
TIO truncates the output since it exceeds 128 KiB.
convey, 8 bytes
1/.]
1+}
Uses the indices command (/.) with an infinite input to print produce ascending numbers forever. However, they start from zero, neccesitating a +1 to be added. Technically I could reuse the 1s that are produced from the other end of the /., but I couldn't figure out a shorter way to do that, so it ends up going to a sink.
ErrLess, 9 bytes
1}@#a?1+{
Explanation
1 { Push one to the stack }
} { Mark end of "comment" }
@# { Output top of stack as number }
a? { Print newline }
1+ { Add one to top of stack }
{ { Mark start of "comment" (skip adding another 1 to the stack) }
ABC, 4 bytes
acal
a increments the accumulator at start, c outputs it, then a increments again, and l loops to beginning.
VBScript, 34 bytes
n=1
Do
Wscript.Echo n
n=n+1
Loop
JavaScript (ES6), 22 21 bytes
for(i=0n;;)alert(++i)
This uses BigInts, which can go to high integers without losing accuracy. Per earlier submissions, I'm assuming that using alert, with its automatic separation between popups, means that outputting an extra character is not necessary.
Scratch 3.0, 57 bytes
57 bytes using scratchblocks syntax, 6 blocks total. say might not be an acceptable form of output because there are no separating characters, so inform me if that's the case.
when gf clicked
set[n v]to[
forever
change[n v]by[1
say(n
05AB1E, 3 bytes
∞€,
tio.run truncates the input, but in theory this would count forever. Also on tio.run, there's a [ at the beginning which I don't know how to get rid of.
Explanation
∞ # push infinite list ([1, 2, …, ∞])
€ # pop a; apply next command for each in a
, # pop a; print(a) (with newline)
Stax, 3 bytes
VIm
the other Stax answer is invalid since it starts from zero. This is shorter, anyway.
v³, 3 bytes
+.=
Unwrapped:
+
. = . .
.
Simple explanation:
+ Add one to memory cell (starts at zero)
= Print memory cell as number
. No-op
The instruction pointer starts at '+' then "falls" into '=', then the '.' at the bottom.
The IP then falls to the '.' on the far right, as if the code is mapped onto a cube.
The IP then falls to '+', completing the loop.
Elixir, 40 bytes
f=fn f,i->IO.puts i;f.(f,i+1)end
f.(f,1)
Strangely enough, up to this point the leaderboard snippet doesn't list any answers in languages starting with E. Let's fix this!
Anyway, Elixir isn't a very convenient choice for this task, as to my knowledge it doesn't have a truly concise way of creating infinite loops/enums, named lambdas can't be recursive, while normal named functions can only be declared within a module. Therefore, we resort to a trick, where we create a named lambda, and pass it to itself as one of the arguments. Hacky, but still shorter than using a conventional way of creating an endless iterator:
Elixir, 45 bytes
Enum.map Stream.iterate(1,&(&1+1)),&IO.puts/1
Pushy, 4 bytes
1$#h
1 % Push 1
$ % While loop (see below):
# % Output last item
h % Increment last item
The while loop will keep running while the last value on the stack evaluates to true. Because all values except 0 are truthy in Pushy, this loop will never exit. The ; to end the loop is assumed by the interpreter.
This should eventually reach 2^128 as specified, because Pushy uses Python 3 (arbitrary sized) integers.
Billiards, 15 bytes/11 characters
Inspired by PhiNotPi's Challenge
1/\
↥↑
\^/
Explanation: 1 summons a ball with value 1. It falls onto the \, which deflects it into the ^.
Then, it levitates from the ^, goes to the ↥ which prints its value. Then it deflects off the /, and then hits the \ and begins falling again. It hits the ↑ which increments its value, and then hits the / and deflects back into the ^.
Bonus: Replace 1 with a to output the starting point.
Bonus: Add b to the end of the first row and < to the end of the last row to specify the ending point.
Braingolf, 15 bytes
V# R1[l!_v!@R>]
Explanation:
V# R1[l!_v!@R>]
V Creates new stack and switches to it
#<space> Pushes 32 (ASCII value of a space) to stack
R Return to main stack
1 Push 1
[........] do-while loop. Will always run once, then checks if
first value in stack is 0 after each loop, if it is,
breaks out of the loop
l Push current length of stack
!_ Print last item on stack without popping
v Switch to next stack
!@ Print last item on stack as ASCII char without popping
R Return to main stack
> Move last item to the start of the stack
Bash, 25 bytes, possibly invalid
while :;do echo -n 1;done
Outputs infinite 1s. In other words, outputs all numbers 1.. in unary, separated by 1 :^)
This is definitely dubious, but I see nothing in the rules or comments that disallows it. I also didn't see an existing submission that uses this gimmick.
This solution could be smaller in other languages, but we need bash in order to be able to output in unary. Since bash has no numbers, I feel it qualifies.
It could probably be smaller in bash too. Unfortunately, I don't know much bash.
Arn, 4 bytes
ëçJx
Explanation
Unpacked: [1{+1
A sequence in arn is defined within [..]. A sequence is made up of hard-coded digits, a block determining how future entries are calculated, and (possibly) an array pointing towards the length of the sequence.
In this case, it is simply defining a sequence where the first entry is 1, and every future entry is 1 higher. Because of Arn's implied closings, the final }] can be removed. Arn uses BigInts.
CJam, 7 bytes
X{_p)}h
Really feels like there should be a way to take off one or two bytes, but oh well.
X Initialize the stack with 1
{ Begin loop
_p Duplicate top of stack and print
) Add 1
}h Loop while top of stack is truthy (non-consuming)
Brainetry -w 0, 63 bytes
Golfed version:
a b c d
a b c d e f g h
a b c d e f g
a b c d
a b c d e f g h i
We use -w 0 otherwise we can only count up to 255. If we add the --numeric-io flag we can also get the output as actual integers instead of codepoints.
The golfed version was adapted from the program at the end of this answer. To try this online you can
- head over to this replit link, copy&paste the code into the
btry/replit.btryfile and hit the green "Run" button; - clone the github repo and from your terminal run
./brainetry btry/ppcg/infinite_count.btry -w 0 --numeric-io.
Original program:
This program runs forever.
Not only it runs forever but it also
prints all natural numbers starting from one.
What a simple task.
I did it in just five lines of code.
Python 3, 24 bytes
i=1
while[print(i)]:i+=1
[print(i)] is a list containing 1 element, which is always truthy. Thus the loop is repeated infinitely.
DIVCON, 4 bytes
S#o+
Explanation
S No-op
# Skip the following:
o Output
+ Increment the accumulator
o Output the incremented accumulator
# If acc != 0: (in which it already is)
S Reverse computation
And it continues, forever ...
Microsoft PowerPoint (33 Slides, 512 shapes to meet minimum requirements)
Storage representation is in hexadecimal.
Directions
- Click the blue square to advance the counter (or propagate the carry), or make an AutoHotKey Script to click it for you.
- You can view the number's digits at any time using the green buttons. (It causes unintended behavior if you click the blue buttons after viewing another digit.) This is just for a better UX. It still counts up as normal as long as you keep clicking the blue button. In other words, no user decision is required.
- If you reach the end, it displays a congratulatory message.
You can get the PPTX here. Requires PowerPoint to run.
Before you comment that Microsoft PowerPoint is not a programming language, it has been shown that PowerPoint is Turing complete (in the same sense that conventional languages such as C are Turing complete). A brief discussion is given here.
Python 3, 53 bytes
import itertools
for i in itertools.count(1):print(i)
Explanation
I prefer to avoid while loops in my code, therefore I decided to write the program.
import itertools # Pretty simple, import something
for i in itertools.count(1): # Foreach in the infinite list from 1 to ∞
print(i) # Print the current item
C# .NET 4.0, 111 103 102 97 bytes
class C{static void Main(){System.Numerics.BigInteger b=1;for(;;)System.Console.WriteLine(b++);}}
I didn't find any C# answer here, so I just had to write one.
.NET 4.0 is required, because it's the first version that includes BigInteger. You have to reference System.Numerics.dll though.
With indentation:
class C
{
static void Main()
{
System.Numerics.BigInteger b = 1;
for (;;)
System.Console.WriteLine(b++);
}
}
Thanks to sweerpotato, Kvam, Berend for saving some bytes
W, 3 bytes
iaE
Explanation
W allows infinite lists, so this simply loops over the infinite list.
i % Unsurprisingly, a built-in for positive infinity.
E % Foreach the infinite list
% from 1 to infinity:
a % Print this item
% with a newline
tinylisp, 33 bytes
(d f(q(l(f(a(h l)1)(disp(h l
(f 1
This is a golf of DLosc's answer, but different enough I thought it would deserve its own answer.
The interpreter fills out )s at the end of a line.
(d f (q vars body)) define f to be (q vars body), this form indicates to tinylisp f is a function taking as arguments vars returning body. vars is l in case, so all the arguments to f get put into a list and passed to l (had v been parenthesised, like (n) in DLosc's answer, f would be defined to only take 1 argument n).
The complete body is (f(a(h l)1)(disp(h l))) (3 trailing )s filled by tinylisp). This calls the function f with the arguments (a(h l)1) and (disp(h l)), which when called will let f see them through l as a list containing both of these arguments. (a(h l)1) adds 1 to (h l), the head of l. This is the counter. The second argument is (disp(h l)) which displays (h l) the head of l (the counter), and returns (). This second argument never gets used but using disp here allows the f to print every cycle.
The loop is started by (f 1) which calls f with l as the list of all the arguments, i.e. (1), the head of which is the counter.
MathGolf, 5 4 bytes
Åîo▲
Thanks to @maxb for explaining how to do an infinite loop in MathGolf.
Explanation:
▲ # Do-while true by popping the value,
Å # with two commands within the loop-body:
î # Push the 1-indexed loop-index
o # Print it with a trailing newline without popping
Note that just like in Python, a positive integer is considered truthy, which is why we print the loop-index without popping so the while(true) can continue.
Haskell, 21 bytes
main=mapM_ print[1..]
Arbitrary-precision integers and infinite lists make this easy :-)
Luckily mapM_ is in the Prelude. If Data.Traversable was as well, we even could shrink it to 19 bytes:
main=for_[1..]print
Runic Enchantments, 446 bytes
\DB͍R"000000000000000000000000000000000000001"$
.{ww;'''''''''''''''''''''''''''''''''''''''
.10{BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
a+'0000000000000000000000000000000000000000
kk0~111111111111111111111111111111111111111
$:{~+++++++++++++++++++++++++++++++++++++++
1'~}567890123456789012345678901234567890123
J://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
.=? 000001111111112222222222333333333344444
/\/v\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
This one took me a while. Runic is not set up to handle arbitrarily large values. The C# interpreter is limited by the fixed bit width of the value types involved, none of which are 128 bits wide and no language commands result in a BigInt being pushed to the stack.
So, instead, I used a string. But decomposing a string into that many characters (and then concatenating them back together again) is a nightmare (especially with that many digits as the instruction pointer starts to fizzle when its stack is too big--there are limited workarounds to that, but this setup works for actually arbitrarily large values, provided that the program is made bigger to accommodate; question specification only required up to 2128 which requires 39 digits; each additional power of 10 adds 10 bytes), so instead the storage is done inside the source code and updated with reflection. I also saw no clarification on whether or not leading 0s were allowed or not, but having them made things much easier.
Image depicts fewer decimal digits for brevity as well as the Red/Yellow/Purple sections offset by 1, due to an old version of the code.
- Cyan: Entry point and output. Reads a string value, pushes it to output, prints a newline, increases mana by 1 (reflection costs 1 mana; image is missing this command), and then enters the blue section via torodial edge wrapping.
- Blue: Read character from the string, edge wrap to Green.
- Green: push
xposition of the read character (in a consistent format, largely for convenience of the programmer), push1,1and Branch to position1,1(Red). - Red: rotate character to top of stack, add 1, convert to character, duplicate, compare with
:('9'+1equals:). If true, go to Yellow. Else go to Purple. - Yellow: Toss out the Branch return coordinates, push a
0(y coordinate for the write command), write the value, proceed to Cyan. - Purple: Toss out the top of the stack (the
:), push a0(y coordinate for the write command), push a'0'character, write the0, return to Branch entry (Salmon) using the modified form,B͍which does not push return coordinates (so two giant rows of~aren't needed). - Salmon (was supposed to be Orange): Repeat steps Blue and Green on the next power of 10.
If it ever fills the entire string with 9s, the next loop would replace it all with 0s and hit the terminator ;. As the online interpreter has a built-in arbitrary maximum execution limit (not including TIO's external limits), this will never actually occur, but that's an implementation detail and not imposed by the language specification.
Deoxyribose, 35 29 bytes
ATGCCAGAAAAACATAACGGTTTAAATCC
Explanation:
ATG
CCA (*) Divide (null/null yields 1)
GAA Dupe
AAA Pop
CAT Push
AAC 1
GGT Move
TTA Plus
AAT Loop
CC *
I feel like this can get shorter.
Edit: Saved 6 bytes by making creative use of division of two empty stacks.
Alchemist, 19 bytes
0a->Out__+Out_" "+_
Prints numbers separated by spaces.
Explanation:
0a-> # While there are no a atoms (i.e. always)
Out__ # Output the number of _ atoms
+Out_" " # Print a space
+_ # Add an _ atom to the environment
Chip, 2214 bytes
Noncompeting: this uses language features that post-date the challenge. For a competing entry that is too inefficient to run, see the edit history.
2211 bytes for the code, plus 3 bytes for the -w flag.
o z*
`K\' ,--K ,--K ,--K ,--K ,--K ,--K ,--K8 ,--K ,--K ,--K ,--K ,--K ,--K ,--K ,--K
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o
o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o,' o#-o
`---' `---' `---' `---' `---' `---' `---' `---' `---' `---' `---' `---' `---' `---' `--'
=
o-----)-------------------------------------------------------------------------------------------------.
`z--z------z------z------z------z------z------z------z------z------z------z------z------z------z------z-K----.
o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a o-zo/a
oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b oz-o/b
o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c o-zo/c
oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d oz-o/d
o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e o-zo/e
oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f oz-o/f
o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g o-zo/g
oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h oz-o/h
This solution gives output in 128 bits / 16 bytes, big endian. It has two main sections, one for incrementing, and the other for timing, storage, and output. There is likely a smaller implementation out there, but I haven't yet conceived of it.
Try it online for the 128-bit version.
Try it online for the 16-bit version, much faster than the 128 bit version.
Notes about the TIO: The -v flag is included, which shows the actual incoming/outgoing binary on stderr. In the TIO, we also provide a -cN flag, which cuts off the program after N bytes have been produced.
Explanation
Chip is a (mostly) 2D language that operates on individual bits, which is why it needs a lot of space for 128-bit support. I won't get into the specific details (because we'd be here all day), but here's the gist of what's going on:
- Layers:
=
This is a layer divider. Lines above form the first layer, lines below form the second. Wherever there areo's on both layers, a connection is formed. - Incrementing:
K ,-- o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | o#-o | `---'
Each#is a half-adder, and each column of#serves to increment the eight inputs on the left to the eight outputs on the right. TheKat the top is a caching element to help with call stack efficiency. The tail is a wire to bring the carry back up to the next incrementor. There are sixteen such incrementors, for the sixteen bytes required to produce 128 bits. The8seen near the eighth incrementor is used for cache priming. This element is always the first element polled each cycle, and so it primes all caches to it's left. This prevents a stack overflow when we eventually compute the values to the right. - Storage:
o-zo oz-o o-zo oz-o o-zo oz-o o-zo oz-o
Eachzreads a signal in on its top/right, and outputs that signal to the bottom/left. Therefore, these columns act as registers to hold the current state for the next cycle to use. Thez's are offset from each other to prevent cross-talk. Again, sixteen such columns, one per byte. - Output:
o/a o/b o/c o/d o/e o/f o/g o/h
The lettersathroughhcorrespond to each of the bits of the byte that will be output, withabeing the least signficant bit. The columns of/'s are switches that interact with the timing circuit to determine which byte is due to be output. Once more, sixteen columns, one per byte. - Timing:
o z* `v\'
o------------- `z--z------z--
The timing circuit consists of two parts. The portion on the first layer produces a high signal on the first clock tick only (to get it all started) and connects the rest of the timing circuit to the incrementors (increments by 1 only every 16th tick, increments by 0 otherwise). The portion on the second layer controls the actual sequencing. The pattern is to increment the value and output the highest byte, then output each successive byte without incrementing anything. When all bytes have been printed, the cycle repeats. (There is a cache elementKand an or-gate)that acts as a diode; these are again for efficiency only.)
Brachylog, 4 bytes
ℕ₁ẉᶠ
Explanation
ℕ₁ -- Get a integer which is at least 1
ẉᶠ -- and print all possible values (ordered from 1 to inf)
Pip, 6 bytes
W1P++i
Straightforward; in pseudocode, this is
while(1)
print(++i)
where i is preinitialized to 0.
Yabasic, 14 bytes
Script that counts from 0 to 2^1024 then outputs Inf, infinitely. Takes no input and outputs to the console.
Do?i
i=i+1Loop
Far More Interesting Version, 20 bytes
For some reason, 0/0=2^1024 in Yabasic, and the language appears to have no loss of precision on this range so rather than producing an error, the following code counts exactly from 0 to 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368, which is wonderful, and stupid :P
For i=0To 0/0?i
Next
Flobnar, 15 bytes
\@
+_
<.9,!
>:
Uses the -d flag in order to output in decimal. The separator between numbers is the tab character
Noether, 6 bytes
(!iP?)
The online link has a delay of 1 second added to prevent the interpreter from freezing up.
Foam, 22 bytes
0[[+1 : <#]/-\ : ~]: ~
Visual Basic .NET (.NET Core), 76 bytes
Declared subroutine that takes no input, and increments then outputs i forever.
Module M
Sub Main
Dim i
Do
i+=1
Console.WriteLine(i)
Loop
End Sub
End Module
Stax, 4 bytes
0W^Q
Added for completeness.
Explanation
0 Pushes 0
W Loop forever
^ Increment
Q Peek and print with newline
Wumpus, 5 bytes
)=O
N
Explanation
The program runs )=ON in an infinite loop (see the "cat" answer for why that is).
) Increment the top of the stack. Initially, this turns an implicit zero
into an explicit one.
= Duplicate.
O Print as a decimal integer.
N Print a linefeed.
Julia 0.6, 30 bytes
for i=1:big(2)^999 @show i end
Outputs lines like i = 1, i = 2. If the i = is disallowed, then for i=1:big(2)^999 println(i) end is 32 bytes. This will count to 2^999, well over the 2^128 required. You can increase that significantly with no additional bytes with big(2)^9^9 but it times out in TIO. big(2) is an arbitrary precision integer, and all math with smaller integer types promotes to arbitrary precision.
tinylisp, 34 bytes
(d f(q((n)(i(disp n)1(f(a n 1
(f 1
The program defines a function f that takes one argument n, prints it, and recurses on n+1; then it calls f with an initial argument of 1. Because tinylisp has tail-call optimization, infinite recursion is not a problem--the implementation handles it as an infinite loop instead.
Pyt, 6 bytes
0`⁺ĐƤł
0 pushes zero ` starts a while non-zero loop (but isn't checked until close loop) ⁺ increments x Đ Duplicates x Ƥ Prints with a separating newline ł go back to ` and loop till top is zero
AutoHotkey, 27 bytes
Based on Michelfrancis' answer: https://codegolf.stackexchange.com/a/78480/72779.
(Should I post this as a reply instead? Pretty new to this, but I don't have enough reputation to reply to other answers anyway.)
c=0 ; Colon-equal operator not required. Saves one byte.
Loop{ ; Removed space between Loop and {. Saves one byte.
c++ ; Shorter incremeting method, removed tab. Saves four bytes.
tooltip %c% ; Removed tab. Saves one byte.
}
Retina, 13 bytes
+\`^.*
$.(*__
Explanation
Retina 1.0 has a new feature which lets us solve this with an algorithm that conceptually uses a unary representation of the number, but still won't run out of memory. You can test this by initialising the string to a really high number, in that case the program will count from there.
So incrementing decimal numbers isn't really something Retina does, because it only works with strings. Leaky Nun has shown a way to increment decimals, but it's comparably complicated.
What Retina can do with decimal integers is a) repeat a character or string n times and b) measure the length of a string. So the idea is to take the last integer n, generate a string with n+1 characters, and measure its length, and use this as our new result. That's what the code does:
^.*match the current string. We need to use.*instead of.+because the string is initially empty (the program's input), and^because.*would otherwise yield two matches on subsequent iterations.- We substitute the match with
$.(*__. There is some implicit syntax going on here. The)is closed implicitly and*has an implicit left-hand operand of$&, so this substitution is really short for$.($&*__).$&*_generates the string of n underscores (when$&is empty, i.e. on the first iteration, it is treated as zero). The second_appends another underscore to that, generating a string of n+1 characters.$.(…)measures the length of that string, so we end up with the next integer. \tells Retina to print the result of this substitution with a trailing linefeed.+runs the entire thing in an infinite loop (+-loops can terminate, but this one won't).
So why does this work for large integers without running out of memory? Retina's $.(…) computation is lazy! Whenever possible, its string argument isn't actually fully evaluated, but its length is computed directly instead. And it knows that a string formed with n*s is n*len(s) characters long. This feature gives us the convenience of a unary approach without the memory requirements. The length computation also uses an arbitrary-precision integer type, so that we can go well beyond 2128.
brainfuck, 31 bytes
->+>+[[<.+]->-[->-]+>[->]<[>]+]
Prints the binary value of each number with char code 1 as 1, null byte as 0 and ÿ as the separator.
The output is the exact same as the previous brainfuck answer, however this can go as high as 2^29998 in the 300000 available brainfuck cells and is 13 bytes shorter.
Pyt, 6 bytes
1`Đƥ⁺ł
Explanation:
1 Push 1
` ł Loop while top of stack is not 0
Đƥ Duplicate top of stack, then print
⁺ Increment top of stack
JavaScript (ES6), 56 Bytes, optimized from user81655
for(n=[],i=99;;)if(n[i]=-~n[i--]%10)alert(n.join``,i=99)
Alumin, 6 bytes
hqhanp
Alumin is a new language, made by @Conor O'Brien.
Explanation:
hqhanp
h # Push 1
q p # Begin/end loop
ha # Push 1, add top two stack elements together (increments top)
n # Prints the top of stack as a number
Aceto, 5 bytes
IkpnO
Explanation:
Aceto follows a Hilbert Curve on a square program. If the program is not square, spaces are added to the top and right. (spaces do nothing) I
I - pops a value, increments it, and pushes it back on
k - makes the stack 'sticky', meaning that when popping a number, instead of removing the value it copies it
p - prints the top value
n - prints a newline
O - Returns the program back to the beginning
Also, can anyone explain to me why 'k' is needed? Shouldn't 'I' do the job just fine? When I omit 'k', it prints out lines and lines of '1's.
TrumpScript, 117 bytes
am is 1000001
an is 1000000
As long as,an is an?;:
say am minus an
am is,am plus 1000001 minus an;!
America is great.
What, there was no TrumpScript submission? Well, now there is. I don't think we can golf it any further though.
Implicit on TIO, 6 4 bytes
(.%ß
This requires that the input box on TIO is empty.
(.%ß
(... « loop while top of stack truthy »;
. « increment top of stack (read input if stack empty) »;
% « print integer »;
ß « print space »;
« just kidding, loop forever »;
><>, 15 Bytes
0>1+:n\
\og10/
Start with zero. Add one, print the value, and then print the character at (0,1) in the codebox, which is a space. Repeat ad nauseam.
TI-BASIC (Z80), 152 bytes
Hex dump:
2a31323334353637383904aa003f2a3004aa013fd1313fdeaa013fbb2baa0104413f3104463fd1416c3040463fbb0caa012b412b31116a2a3904463f41713104413fd43fce463fcf3f2a313fd03fbb0caa002b3170bb2abb0caa012b4170312b3111112b313fce413fbb0caa012b312b411170723fd43fd3492b312bbb2baa0111714171b8463f72702a303fd43f7204aa013fd4
Token rendering:
"123456789→Str1
"0→Str2
While 1
Disp Str2
length(Str2→A
1→F
While A>0 and F
sub(Str2,A,1)="9→F
A-1→A
End
If F
Then
"1
Else
sub(Str1,1+expr(sub(Str2,A+1,1)),1
If A
sub(Str2,1,A)+Ans
End
For(I,1,length(Str2)-A-not(F
Ans+"0
End
Ans→Str2
End
Implements incrementing on string-based decimal arbitrary-precision nonnegative integers. I haven't put much effort into golfing this, since just working with strings in this language is already hard enough.
The program should work on the whole TI-83 through -84 series (tested on the TI-84 Plus SE).
Encoding
TI-BASIC code, like all text on the TI-8X, uses its own token-based encoding (see these token tables provided by a third party).
Output
Output is in decimal through Disp, which essentially prints a string on its own line. On the TI-83 through TI-84 Plus SE calculators, once the numbers get large enough that they no longer fit on the display they'll appear truncated with ellipses in the last column. This is by far the TI-BASIC output method closest to standard out.
Anyfix, 6 bytes
This was intended to be a language that allowed programs to be prefix, infix, and postfix, sometimes all at once. However, because of the way it works, dyads and tryads will default to prefix and monads will default to postfix. It's quite confusing. (Inspired by Jelly and 05AB1E)
1¿"Ƥ‘»
Explanation
1¿"Ƥ‘» Program
1 Push 1 onto the stack
¿ If the stack is non-empty, then look at the top of the stack off and execute the next token if that value is truthy
"Ƥ‘"» ComboToken:
" Duplicate the top of the stack
Ƥ Pop and print with a trailing newline
‘ Increment the value
Since this is written in Python, it can easily count up to way past 2 ** 16384... hehe
This language will be on TIO sometime in the future once Dennis has some time to spare.
Triangular, 15 10 9 bytes
-5 thanks to caird
\#iA.,/%<
Formatted:
\
# i
A . ,
/ % < ÿ
Redirects/bounces only:
\
. .
. . ,
/ . <
So the code i%A# is repeated infinitely.
i- increment top of stack%- print top of stack as integerA- push 10#- print top of stack as ASCII and pop
Brainfuck, 1055 bytes
+>+<[>[>[-]+<-]>[<+>>>>>>>>>[-]>[-]<[>+<-]<<<<<<<<-]>>>>>>>>>>>[<<<<<<<<<<<<+>>>>>>>>>>>>-]<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>+>[-]<[>+<-][-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[-]<<[<<<<<<+>>>>>>-]->>[<<<<<<<<-<+>>>>>>>>>-]<<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]>[>>>>>>+<<<<<<[-]]<->>>>>>>[<<<<<<<->>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[>>>>+<<<<<<<<<<<<<->>>>>>>>>[-]]<<<<<<<<-]<[>[-]+<-]>[<+>>>>>>>>>>>>>>+<<<<<<<<<<<<<<->-]>>>>>>>>>>>>[<<<<<<<<<<<<<+>>>>>>>>>>>>>-]<<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>[-]>[-]>[-]>[-]>>>[<<<<+[>+<<<<+>>>-]<<<[>>>+<<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>>+>[-]<<<-]>>[>>+<<<<+>>-]<<[>>+<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>+>[-]<<-]>>>>>>>-]<<<<<<[<++++++++[>++++++>++++++<<-]>.>.[-]<[-]]>[<<++++++++[>>++++++<<-]>>.[-]]<<++++++++[>>>++++++<<<-]>>>.[-]<<<++++[>++++++++<-]>.[-]<>>>>>>>>>>+<<<<<<<<<<<<->-]>>>>>>>>>>>>>[<<<<<<<<<<<<<<+>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>[-]+<-]>[<+<->>-]<<]
Too bad that Brainfuck has limited memory cell size. Actually, printing decimals and conditional statements are pain in this language. Ungolfed (or called so):
+>+<[
COUNTER=0
>[>[-]+<-]>[<+
>>>>>>>>>>[-]
LOOP START
INCREMENTING <<<<<<<<<-]>>>>>>>>>>>[<<<<<<<<<<<<+>>>>>>>>>>>>-]<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>+>[-]<[>+<-]
CHECKING CELL [-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[-]<<[<<<<<<+>>>>>>-]->>[<<<<<<<<-<+>>>>>>>>>-]<<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]>[>>>>>>+<<<<<<[-]]<->>>>>>>[<<<<<<<->>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[>>>>+<<<<<<<<<<<<<->>>>>>>>>[-]]<<<<<<<<-]<[>[-]+<-]>[<+>>>>>>>>>>>>>>+<<<<<<<<<<<<<<->-]>>>>>>>>>>>> [<<<<<<<<<<<<<+>>>>>>>>>>>>>-]
PRINTING
<<<<<<<<<<<<<[>[-]+<-]>[<+
PRINT INTEGER
>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>[-]>[-]>[-]>[-]>>>[<<<<+[>+<<<<+>>>-]<<<[>>>+<<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>>+>[-]<<<-]>>[>>+<<<<+>>-]<<[>>+<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>+>[-]<<-]>>>>>>>-]<<<<<<[<++++++++[>++++++>++++++<<-]>.>.[-]<[-]]>[<<++++++++[>>++++++<<-]>>.[-]]<<++++++++[>>>++++++<<<-]>>>.[-]
PRINT SPACE
<<<++++[>++++++++<-]>.[-]<
LOOP END
CODE THAT GETS EXECUTED AT THE END (LEAVING LOOP):
>>>>>>>>>>+<<<<<<<<<<<<->-]>>>>>>>>>>>>>[<<<<<<<<<<<<<<+>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>[-]+<-]>[<+<->>-]<<]
If we would remove last piece of code it would stick two '1' at the end.
Swift 4, 146 bytes
var a=[0];while true{var e=a.count-1;print(a.reduce("",{$0+"\($1)"}));while e>=0{a[e]+=1;if a[e]<10{break};a[e]=0;if e==0{a.insert(1,at:0)};e-=1}}
The code compiles as is from a .swift file using swiftc. The program outputs numbers in decimal form, and given enough time it will output 2128 (and beyond).
Ungolfed (and slightly modifieda) version: Swift Sandbox.
a: Starts just shy of 1040 (larger than 2128) and ends execution at 1040 exactly.
JavaScript (ES6), 74 69 chars
Output is binary.
for(r="1";;r=r.replace(/(?:(^1)|.)(?=1*$)/g,(m,f)=>f?10:m^1))alert(r)
Cubically, 12 11 bytes
R3D1R1(+0%6)
Explanation:
R3D1R1 get UP's faceval to 1
( open loop that can always be jumped to
+0 add 1 to notepad
% print notepad
) loop
Casio Basic, 27 bytes
For 1⇒z To ∞
Print z
Next
The largest integer the fx-CP400 can store precisely is a bit over 22032, or 611 digits. Chances are it'll keep counting up to 101000 before overflowing, though.
cQuents, 1 byte
$
Explanation
: Implicit mode : (infinitely print the sequence if given no input)
$ Each item in the sequence equals the current (1-based) index
Whitespace, 40 bytes
Outputs numbers separated by newlines. Whitespace numbers are integers of arbitrary length however certain interpreters may impose their own limits due to the implementation language. As a counterexample, whitespace.pl theoretically should be able to output forever as Perl supports arbitrary length integers.
Explanation
(s - space, t - tab, n - newline)
sssn # push 0 - stack: [0]
nssn # label ''
ssstn # push 1 - stack: [<n-1>, 1]
tsss # pop and add the top two items, push result - stack: [<n>]
sns # duplicate the top item - stack: [<n>, <n>]
tnst # pop, print as num - stack: [<n>]
ssststsn # push 10 - stack: [<n>, 10]
tnss # pop, print as char (LF) - stack: [<n>]
nsnn # jump to label ''
Groovy, 25 bytes
for(i=1g;;i++){println i}
Groovy allows numeric literals of type BigInteger or BigDecimal to be declared by using the suffix g. BigNumber types are arbitrary length/precision numbers. This code declares a BigInteger then continuously prints (with a newline) and increments it.
ArnoldC, 157 bytes
IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP 0
STICK AROUND 1
GET TO THE CHOPPER n
GET UP 1
ENOUGH TALK
TALK TO THE HAND n
CHILL
YOU HAVE BEEN TERMINATED
First time trying to use ArnoldC so any improvements are welcome. I ran it here and it seemed to work even though the output stops around 1700. I believe this is a limitation of that test though, not the code.
Fourier, 10 bytes
(i^~io32a)
A very simple program that loops forever.
Note, the program on FourIDE has been modified to make it more readable: it has a delay of two seconds between each number
Swift - 32 bytes
for i in 0...Int64.max{print(i)}
Swift - 33 bytes
var i=0;while true{print(i);i+=1}
Cannot provide a testing link, because on the online environments this produces a buffer overflow. However, you can test it in Xcode / Swift Playgrounds or if you have an apple computer, you can run it in the Terminal, after typing the 'swift' command and pasting the code in.
Alice, 6 bytes
h .\
O
Alice is a 2D language with two modes - Cardinal (up/down/left/right) for integers and Ordinal (diagonal) for strings. For this challenge we need Cardinal to count and Ordinal to print as an integer (as opposed to a byte).
We start off from the top left in Cardinal mode, with h incrementing the top of stack — for the first iteration, this is an implicit 0. The space that follows is a no-op, and the . after duplicates the top of stack.
Next we pass through the mirror \, reflecting us NE and switching us to Alice's Ordinal mode. In Ordinal mode the IP reflects off the code boundary rather than wrapping around, so we rebound and start moving SW.
From here we bounce twice, hit the O to print as integer, and bounce back to the \. This switches us back to Cardinal mode moving rightward, wrapping around and continuing the infinite loop.
TL;DR:
0123 -> h5.3 -> h7 9 -> 01.9 -> ...
O 6 4 6 8 O
QBIC, 8 bytes
{n=n+1?n
Explanation:
{ Start an infinite loop
n=n+1 Increment n (starts at 0)
?n PRINT n
Loop closed implicitly
Runs better tan expected. QBIC, when run in QBasic 4.5 on DOSBOX handles numbers up to and including 2^128 quite well, but it has a tendency to use scientific notation for the bigger numbers.
VBA, 157 103 bytes
The Variant / Decimal data type in VBA only allows up to 29 digits of precision. 2^128 is 39 digits long so we have to smoosh two variables together. Variant is the default for any undeclared variable so that's easy. Every time the right-hand side (a) rolls over, set it back to 0 and iterate the left-hand side (b) by 1. To handle leading zeros, we set the format to be 28 digits long the first time that a rolls over. This has a smaller max than the string method but it's well above 2^128.
Sub c()
Do
a=a+1
If a=10^28Then b=b+1:a=0:f=Replace(Space(28)," ",0)
Debug.?b &Format(a,f)
Loop
End Sub
Once it's formatted for humans, it looks like this:
Sub c()
Do
a = a + 1
If a = 10 ^ 28 Then b = b + 1: a = 0: f = Replace(Space(28), " ", 0)
Debug.Print b & Format(a, f)
Loop
End Sub
Previous method using strings:
It starts with the right-most character, converts it to a number, and then keeps moving left until the result is less than 10.
Sub d()
s="1"
Do
Debug.?s
For i=Len(s)To 1Step -1
c=Val(Right(s,1))+1
s=Left(s,i-1)
If c<10Then Exit For
If i-1Then r=r &"0"
Next
s=s &c &r
r=""
Loop
End Sub
REXX, 34 bytes
numeric digits 39
do #=0
say #
end
(If your interpreter is set to a suitably large default precision, you may skip the numeric digits line.)
stacked, 12 bytes
[1+out]0 ani
This works as follows:
[1+out]0 ani
[ ]0 ani in an interval of 0 seconds, do:
1+ add 1 to the counter
out output it
SmileBASIC, 87 bytes
S$="0"*#Y@L
I S$,127?S$GOTO@L
DEF I S,P
IF"0"<S[P]THEN S[P]="0"I S,P-1 ELSE S[P]="1
END
Uses a recursive function to increment a binary string.
Perl 6, 13 bytes
.say for 0..*
Perl 6 has lazy/infinite arrays, so I'm abusing that to create an infinite range. This will never run out of memory.
Note: as explained in the Perl 6 docs, (0..*)>>.say would print out of order.
PHP, 95 74 64 bytes
<?for($n=_;;print strrev($n))for($i=0;!$n[$i]=($n[++$i]+1)%10;);
or
<?for($n=_;;print strrev($n))while($i*=!$n[$i]=($n[++$i]+1)%10);
http://php.net/bc_installation: These functions are only available if PHP was configured with --enable-bcmath.
http://php.net/gmp_installation: In order to have these functions available, PHP must be compiled with GMP support by using the --with-gmp option.
So I just implemented bcadd ... sort of. Uses underscore as separator.
Befunge - 4 bytes
I’m surprised there isn’t already a Befunge answer on here.
1+:.
Brachylog, 6 bytes
#>=@w\
Explanation
#> Constrain a number in [1,∞)
= Assign a value to the number in that interval
@w Write the number followed by a linebreak
\ False ; try another value assignement in the interval
Sesos, 2 bytes
Hexdump:
0000000: 0c3a .:
Assembly:
set numout ;output one number per line instead of character
nop ;set entry marker (start of loop)
add 1
put
;(implicit jnz) set exit marker (end of loop, jump if not zero)
Oracle SQL, 42 Bytes
select level from t connect by level=level
05AB1E, 4 bytes
[¼¾,
Explained
[ # start infinite loop
¼ # increase counter
¾ # push counter
, # print with a newline
Lua, 27 Bytes
i=1::a::i=i+1print(i)goto a
UGL, 14 bytes
cul$oucuuu$*O:
How it works:
cul$oucuuu$*O:
cu #i=1
l : #while i:
$o # print(i)
u # i++
cuuu$*O # print(chr(9))
Tellurium, 6 bytes
[i|+^]
Pretty simple.
The program adds one to the selected cell (+), and then outputs it (^). Using i as a loop's value makes it run the code forever.
Node.js + Big.js, 63 bytes
Use npm install big.js before running.
c=new require("big.js")(0);while(1)console.log(c+""),c=c.add(1)
Simple enough, and has arbitrary precision. Each number is seperated by newlines.
Retina, 73 bytes
No unary! Taken mostly from this SO answer. As noted by Martin, this code doesn't work in the newest version of Retina. Change (;`(\d+) to {;`(\d+) for it to work.
:`^$
1
(;`(\d+)
0$1~01234567890
:`^0(?!9*~)|(\d)(?=9*~\d*?\1(\d))|~\d*
$2
It is much shorter if it was able use unary.
JavaScript (ES6), 99 94 67 bytes
for(n=[i=0];;)(n[i]=-~n[i++]%10)&&alert([...n].reverse(i=0).join``)
alert is the generally accepted STDOUT equivalent for JavaScript but using it means that consecutive numbers are automatically separated. I've assumed that outputting a character after the number is not necessary because of this.
C++, 72 bytes
Different from the other C++ answer, as it only uses the std library.
Golfed:
#include<iostream>
int main(){for(int c=0;c>=0;c++,std::cout<<c<<"\n");}
Ungolfed:
#include<iostream>
int main(){
for(int c = 0; c >= 0; c++){
std::cout<<c<<"\n";
}
}
AutoHotKey, 34 bytes
Golfed and Ungolfed is the same.
Golfed:
c:=0
Loop {
c:=c+1
tooltip %c%
}
Ungolfed:
c:=0
Loop {
c:=c+1
tooltip %c%
}
Fuzzy Octo Guacamole, 4 bytes
(+X)
Explanation:
(+X)
( ) # Infinite loop.
+ # Increment ToS, which is 0 by default.
X # Print ToS.
# Implicit output applies to the end of a loop.
Retina, 20 bytes
<empty line>
39$*0
+:T`9d`d`.9*$
Can count to 10**39-1.
Without leading zeroes (can count beyond 10**39): 23 bytes
+:(T`9d`d`.9*$
^0*$
1$&
13 bytes if pre-initialized with input as 39 "0"s:
+:T`9d`d`.9*$
Perl, 20 19 bytes
perl -E 's//0/;say while++$_'
Magic string increment makes this work without bigint
Molecule, 7 bytes (6 chars)
0(1+~)
Explanation:
0(1+~)
0 add 0 to stack
( begin while statement
1+ add one
~ print
) goto the beginning of while statement.
PRINDEAL, 21
a c
i n
r
c
a r
p n
c
r
Preceds each number printed with n = , because it is not possible to print without such a prefix in PRINDEAL.
Pylongolf2, 6 bytes
0>1+~<
Have a zero in the stack and continously add up to it.
I could give a more detailed explanation.
Pylongolf2, 20 bytes (bonus)
cn:A0>1+~_A@1=?t¿d<
Only works in beta 6, but this version asks for what number to count to.
Jelly, 3 bytes
Ṅ‘ß
Try it online! Be careful though, since this is a long output after all!
Ṅ Print with newline
‘ Increment
ß Call current link (function) again
Since there are no input arguments, the initial argument is taken to be 0.
Previous version:
Ṅ‘$ÐL
Ṅ Print with newline
‘ Increment
$ Combine previous two
ÐL Loop until
C#, 83 Bytes
using System;class C{static void Main(){double x=0;for(;;)Console.WriteLine(x++);}}
Un-golfed:
using System;
class C {
static void Main(){
double b=0;
for(;;)Console.WriteLine(b++);
}
}
Note: C#'s double type can store values up to approximately 1.79769313486232x10308.
Aubergine, 61 bytes
=A1+i1
=bi-b1-b1:Ba+b1=oB+A1=aA-a1-ii =oB-a1-ii
Try It Online! but be sure to hit Kill quickly so as to not crash your browser!
Prints in unary, one number per line. The Python interpreter, at least, will ensure it runs forever. (Make sure it is EXACTLY 61 bytes if you run it: adjust the number of spaces in the middle if it is not.)
How it works:
=A1 SET MEM[0]=1 (this will be the counter).
+i1 JUMP 1 byte forward. (Skips the newline.)
=bi-b1-b1 SET b=5 (points to the '1'=49 on the prev line)
:Ba JUMP to 49 if a>0 (Will land on the other side of the spaces)
+b1 SET b=6 (now points to the newline)
=oB OUTPUT what b points to (the newline)
+A1 INC MEM[0]
=aA COPY MEM[0] INTO a (but we haven't printed the prev num yet!)
-a1 DEC a (Now a=the prev num)
-ii JUMP to the beginning
(The sixth instruction jumps here when a>0:)
=oB OUTPUT contents of b ('1')
-a1 DEC a
-ii JUMP to the beginning
UberGenes, 33 30 bytes
I'm giving two versions here, just to demonstrate the lang. Integers and memory in UberGenes are bounded only by computer memory, so both versions meet the "forever" requirement. This first one is for score:
=ii+a1=pa=q5=bi-p1=oQ:bp=oI=i0
It prints numbers in unary separated by '=' characters. Explanation (indents indicate a loop start):
=ii NOP
+a1 INC a (initially 0)
=pa COPY a INTO p
=q5 SET q=5 so it points to '1'
=bi SET b to this location (15)
-p1 DEC p
=oQ OUTPUT '1'
:bp JUMP to b's location while p>0
=oI OUTPUT the contents of this location ('=')
=i0 JUMP to the beginning of main loop.
The second version is more interesting (66 bytes):
=ii+a1=l0-l2=pa=z8*z6=t5*t2=bi=qp%qt+qz=Lq-l1/pt:bp=bi=oL+l1:bL=i0
It prints the numbers in decimal separated by NULLs.
How it works (indents indicate a loop start):
=ii NOP
+a1 INC a (initially 0)
=l0-l2 SET l=-2
=pa COPY a INTO p
=z8*z6 SET z=48 ('0')
=t5*t2 SET t=10
=bi SET b to this location (27)
=qp COPY p INTO q
%qt MOD q BY 10
+qz ADD 48 to q (turn it into character)
=Lq PUT q AT MEM[l]
-l1 DEC l
/pt DIVIDE p by 10
:bp JUMP back to b's location if p>0
=bi SET b to this location (51)
=oL OUTPUT the character in MEM[l]
+l1 INC l
:bL JUMP back to b's location if MEM[l]>0
=i0 JUMP back to beginning of main loop
ForceLang, 35 bytes
label l
io.writeln set a 1+a
goto l
ForceLang uses BigRationals as the default number type.
Also, in the latest revision, 1+nil yields 1, which is what allows this version to work (previously it would have yielded the string "1<nil>".)
nil+1, however, still triggers a null pointer exception.
Hoon, 25 bytes
$:|=(a/@ ~&(a $(a +(a))))
Just repeatedly prints the sample of the gate, and recurses with a = a+1. Hoon's native number is a bignum backed by gmp, so it should be able to count up to 2^128 just fine. Simply paste that code into the Hoon repl (:dojo) in Urbit to run it.
It does abuse the feature of Hoon that gates are instantiated with a default sample, though. Pulling the $ arm for the gate runs it immediately, with the sample set to that default instead of having to call it with (f 0). It's actually smaller to do it this way instead of =+(a=0 |-(~&(a $(a +(a)))))
D, 56 57 bytes
import std.stdio;void main(){for(real i;;writeln(i++)){}}
Pretty straightforward. D != Python.
The shortest while-loop version I can think of is longer, at 59 bytes:
import std.stdio;void main(){real i;while(++i){writeln(i);}}
WhoScript, 28 27 bytes
1#1;v;e;pw #;#a;pw;#1;+;i;d
Ungolfed/Explanation:
# 1 @ push 1 to the stack
time_vortex @ begin an infinite loop
duplicate @ duplicates the top of the stack
psychic_paper write # @ prints the top of the stack as a number
# a @ pushes 10 (0xA) to the stack
psychic_paper write @ prints the character whose ASCII code matches the top of the stack
# 1 @ pushes another 1 to the stack
+ @ adds the top two stack values (as a floating point number)
integer @ converts the top number of the stack to an integer
paradox @ go back to the 'time_vortex' line
Shaved off a byte by using 0xA instead of 0x20
F#, 50 49 36 bytes
let rec(!)d=printfn"%O"d;!(d+1I)
!1I
BigIntegers made this pretty easy, although I didn't know I could access them this easily in F#. =)
Update: It's even easier! You don't have to use bigint 1 when you can use 1I! =D
Without using BigInteger, I was able to get it down to 153 bytes. Note that this uses a base 256 representation, with a space between the digits and a newline between the numbers:
let rec i=function|255::[]->0::[1]|255::r->0::(i r)|n::r->(n+1)::r
let rec f d=printfn"%s"(List.rev d|>Seq.fold(fun s c->s+" "+(string c))"");f(i d)
f[0]
The function revolves around treating a list of byte-sized integers as a big number. The recursive function i increments that number (carrying changes up the digits by calling itself if needed), while the recursive function f prints the list as a number, increments the list, then calls itself.
Overall, a pretty fun problem. Thanks! =)
Saved a byte thanks to a trick I saw @Lynn do: name your functions with a character to call them more concisely. Thanks! =)
dc, 12 bytes
Uses an "anonymous" recursive macro, should be able to run for ever:
z[r1+prdx]dx
Bash, 31, 47 46 bytes
for((i=0;;i=`echo "$i+1"|bc`));do echo $i;done
I'm a bash novice but I've been wanting to use bash in code golf for a while. There must be a better way than this though, I'm sure it can be beaten!
I believe this fixes the issues.
> a=$((2**128)) # Too big
> echo $a
0
> a=$(echo "2^128"|bc) # Works!
> echo $a
340282366920938463463374607431768211456
So all expressions are piped through bc to make sure it can handle them. It returns a string representation to the variable, which can then be printed. Open to golfing, maybe I can use bc better or maybe I can do code substitution better.
GNU coreutils, 16 bytes
seq `bc<<<2^225`
GNU seq happily handles values over 2^128. 2^225 is the largest value bc will print without wrapping (it assumes 80-character width), so that's what I've used here.
Here's the proof that we can handle values higher than 2^227 (dc wraps one char later than bc):
$ seq `dc -e2d227^p` `dc -e2d227^10+p`
215679573337205118357336120696157045389097155380324579848828881993728
215679573337205118357336120696157045389097155380324579848828881993729
215679573337205118357336120696157045389097155380324579848828881993730
215679573337205118357336120696157045389097155380324579848828881993731
215679573337205118357336120696157045389097155380324579848828881993732
215679573337205118357336120696157045389097155380324579848828881993733
215679573337205118357336120696157045389097155380324579848828881993734
215679573337205118357336120696157045389097155380324579848828881993735
215679573337205118357336120696157045389097155380324579848828881993736
215679573337205118357336120696157045389097155380324579848828881993737
215679573337205118357336120696157045389097155380324579848828881993738
Y, 9 bytes
0C:' gghX
Simple three-link program. 0C initializes the stack with a 0 and moves to the next link, : duplicates the current value ' pushes a space for a separator, gg prints twice, and h increments it. X is an unconditional wrap-around, so we go to the beginning of the link. Try it here!
Pyth, 4 bytes
.V1b
.V begins an infinite loop which defines incremented b, starting with 1. The body of the loop implicitly prints b on the next line.
Prolog (SWI), 35 bytes
p:-between(1,inf,N),writeln(N),1=2.
Edit: Saved 6 bytes thanks to @Fatalize
BotEngine, 128 120 112 8x13=104
v2 2 01
>e>S SS
e1e1
e2 e0 12
> > S SS P
^ <e0e1 R
^ < <lC^
^ <
Output is in binary.
Seriously, 4 bytes
1W■u
Explanation:
1 puts 1 on the stack
W begins a while loop that executes while the (peeked) value on top of the stack is truthy
■ output entire stack without popping
u increment value on top of stack
<EOF> implicit end of while loop block
No online interpreter link because it doesn't do so well with infinite loops.
Matlab, 95 bytes
for n=1:128;sym(sym(2^n)-1),for i=1:n sym(2^n+sym(sum(power(2,nchoosek(1:n,i)-1),2)-1)),end,end
This program can count over 2^128 just try with these parameters if you have doubts.
for n=200:200;sym(sym(2^n)-1),for i=1:n sym(2^n+sym(sum(power(2,nchoosek(1:n,i)-1),2)-1)),end,endThis can be golfed more if I could figure out a way to combine two loops in one single executive loop, thats because the code skips one integer per 2^k the case of one loop.
Turing Machine Simulator, 536 bytes
a * * r a
a , * r A
A * * r A
A , * l b
b * * l b
b , * l c
b s 0 l 0
b p 1 l 1
b d 2 l 2
b f 3 l 3
b g 4 l 4
b h 5 l 5
b i 6 l 6
b j 7 l 7
b k 8 l 8
b l 9 l 9
0 * * l 0
0 _ s r a
1 * * l 1
1 _ p r a
2 * * l 2
2 _ d r a
3 * * l 3
3 _ f r a
4 * * l 4
4 _ g r a
5 * * l 5
5 _ h r a
6 * * l 6
6 _ i r a
7 * * l 7
7 _ j r a
8 * * l 8
8 _ k r a
9 * * l 9
9 _ l r a
c _ p l d
c s p l d
c p d l d
c d f l d
c f g l d
c g h l d
c h i l d
c i j l d
c j k l d
c k l l d
c l s l c
d * * l d
d _ , r A
Test it out here -> link
initial input: ,*p,
initial state: b
Explanation:
state a: move right until a comma is found then move to state A
state A: move right until a comma is found then move to state b
state b: move left until a letter or a comma is found. If a letter is found, change the letter to its corresponding digit and move to the corresponding state. If a comma is found, move to state c.
states 0-9: move left until an empty space is found then write the digit
state c: increment the number and end up on the left then move to state d
state d: place a comma then move to state A
Basically, it finds the previous number, copies it over while converting it to digits, increments it, then starts all over.
On a real turing machine this would go way over 2^128
Forth, 67 71 bytes
Forth doesn't have a builtin word for exponentiation, so we need to define one, because loops in Forth, which are frowned upon, need clearly defined bounds.
According to the language's original spec, this will segfault or run out of memory when it gets to 32,767 but that's not the case for mighty gforth! Instead, this runs out of memory whenever it's unable to continue storing numbers, as the stack's allocation is not dynamic like the heap's is, and do's operands (the limit and index) are put on the heap, not the stack, else they would interfere with the stack.
Essentially, it will stop at the same point every other answer here will.
The loop construct normally looks like 10 0 do ... loop where 10 is the limit and 0 is the index, i.e starting point.
In this example, we need to add one to the upper bound before counting there.
Edit: apparently do is a "compile-only" word, and it can only be found inside macro definitions.
: p over swap 1 ?do over * loop nip ;
: c 2 128 p 1 + 0 do i . loop ;
c
Mouse-2002, 17 bytes
aa:(a.!"!"a.b+a:)
It seems there's a flaw in the interpreter which messes up using the stack for while loops, I dunno, so we use a variable instead.
Samau, 2 bytes
N)
Explanation:
N push the infinite list [0 1 2 ...] onto the stack
) increase by 1
When the output of a program is a list, the outmost brackets are omitted.
Mathematica, 22 bytes
For[i=1,1>0,Print@i++]
bc, 10
for(;;)++i
Unusual that bc is shorter than dc.
From man bc:
DESCRIPTION
bc is a language that supports arbitrary precision numbers
GNU sed, 36
(score includes +1 for requiring the -r flag)
:=
p
s/$/1/
:
s/(^|_)1{10}/1_/
t
b=
This counts in unary-coded decimal, and must be primed with the starting number in UCD (e.g. 1) on stdin:
$ ./63834.sed <<<1 | head -n 30
1
11
111
1111
11111
111111
1111111
11111111
111111111
1_
1_1
1_11
1_111
1_1111
1_11111
1_111111
1_1111111
1_11111111
1_111111111
11_
11_1
11_11
11_111
11_1111
11_11111
11_111111
11_1111111
11_11111111
11_111111111
111_
Here's a version that takes input and output in decimal (now using x as the digit and 0 as separator):
#!/bin/sed -rf
s/[1-9]/0&/g
s/[5-9]/4&/g
y/8/4/
s/9/4&/g
s/4/22/g
s/[37]/2x/g
s/[26]/xx/g
s/[1-9]/x/g
:=
h
s/0x/-x/g
s/xx/2/g
y/x/1/
s/22/4/g
s/44/8/g
s/81/9/g
s/42/6/g
s/21/3/g
s/61/7/g
s/41/5/g
s/-//g
p
g
s/$/x/
:
s/(^|0)x{10}/x0/
t
b=
This is the same code, but with UCD/decimal conversion going on. This makes it easier to make it start at 2^128:
$ bc <<<'2 ^ 128' | ./63834.sed | head -n 10
340282366920938463463374607431768211456
340282366920938463463374607431768211457
340282366920938463463374607431768211458
340282366920938463463374607431768211459
340282366920938463463374607431768211460
340282366920938463463374607431768211461
340282366920938463463374607431768211462
340282366920938463463374607431768211463
340282366920938463463374607431768211464
340282366920938463463374607431768211465
Brainfuck, 44 bytes
->-<[>>[->>]<[+>>-<<]>+>+[->>+]-<+[-.<<+]-.]
I'm surprised there are no brainfuck submissions, so here's my attempt (and my first brainfuck program). I interpreted the constraint on number formatting as 'whatever is convenient for your language', so the output here is as a binary string of 00 and 01, with FF as separators. The beginning of the output:
0000000: 01 ff 01 00 ff 01 01 ff 01 00 00 ff 01 00 01 ff ................
0000010: 01 01 00 ff 01 01 01 ff 01 00 00 00 ff 01 00 00 ................
The standard 30000 byte BF implementation can go as high as 2^15000 before reaching undefined behavior. Here is another version which produces a more readable output consisting of "0" and "1" with newlines as separators (currently 105 chars, although this can probably be golfed more):
++++++++++>>->-<[>>[->>]<[+>>-<<]>+>+[->>+]-<+[-[-<+<<+>>>]++++++[-<++++++++>]<.[-]<<[->>>+<<<]>+]-<<.>>]
Output:
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
awk , 65 bytes
BEGIN{for(;;){for(;++$++i>9;)$i=0;for(i=NF+1;i;)printf--i?$i:RS}}
Counts up "forever" using the fields as an array. I made sure this works with the standard Ubuntu awk (mawk).
JavaScript, 80 bytes
r=t=>{t=a.pop()||0;if(++t>9){r();t=0}a.push(t)};for(a=[1];;r())alert(a.join(''))
To test at 2^128 in console, for 1000 cycles;
r=t=>{t=a.pop()||0;if(++t>9){r();t=0}a.push(t)};for(x=1,a=[3,4,0,2,8,2,3,6,6,9,2,0,9,3,8,4,6,3,4,6,3,3,7,4,6,0,7,4,3,1,7,6,8,2,1,1,4,5,6];x<=1000;r(),x++)console.log(a.join(''))
And to test all 9s for 2 cycles;
r=t=>{t=a.pop()||0;if(++t>9){r();t=0}a.push(t)};for(x=1,a=[9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9];x<=2;r(),x++)console.log(a.join(''))
My original idea was to actually use objects, but the array idea turned out to be super small. Mine should be the smallest JavaScript one at the moment
Object Oriented: 107 bytes
function d(p){var x=0,s="";this.o=q=>{return++x>9&&(x=0,p=p||new d,s=p.o()),s+x}}for(c=new d;;)alert(c.o())
R, 52 Bytes
a=gmp::as.bigz(1);repeat{cat(paste(a,""));a=a+1}
(Note: gmp is an external library, so you may have to download it for this solution to work)
Python 3, 33 25 bytes
As far as I understand, Pythons integers are arbitrary precision, and print() automatically produces newlines.
Thanks for @Jakub and @Sp3000 and @wnnmaw! I really don't know much python, the only think I knew was that it supports arbitrary size integers=)
k=1
while 1:print(k);k+=1
Clojure, 17 bytes
(map prn (range))
Lazy sequences and arbitrary precision integers make this easy (as for Haskell and CL). prn saves me a few bytes since I don't need to print a format string. doseq would probably be more idiomatic since here we're only dealing with side effects; map doesn't make a lot of sense to use since it will create a sequence of nil (which is the return value of each prn call.
Assuming I count forever, the null pointer sequence which results from this operation never gets returned.
Marbelous, 358 bytes
..@F..@E..@D..@C..@B..@A..@9..@8..@7..@6..@5..@4..@3..@2..@1..@001@Z01
..AddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddoAddo/\&I
00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I00&I....@Z
@FHd@EHd@DHd@CHd@BHd@AHd@9Hd@8Hd@7Hd@6Hd@5Hd@4Hd@3Hd@2Hd@1Hd@0Hd
0A@N
..&I
@N/\..
:Hd
}0
Hp
}0
..
{<
#include hex_out.mbl
#include arithmetic.mbl
16 half adders chained together, the rightmost one performing N++ each cycle and each adder feeding its overflow (00 or 01) to the next in the chain. Output is in hex.
The python interpreter has a bug where output from memoized functions is lost, so you have to run this with "-m 0" to make it work right. Without that parameter you can see how fast it will run without the bug, but the output won't work right.
Note to self: fix that bug in marbelous.py This bug has been fixed in the latest version of marbelous.py
PARI/GP, 23 bytes
i=0;until(print(i+=1),)
Sample Usage
$ gp -qf < countup.gp
PowerShell, 19 14 Bytes
for(){$i++;$i}
Removed echo as per user recommendation
Common Lisp, 30 bytes
(do((i 0))(())(print(incf i)))
or
(do((x 0(1+ x)))(())(print x))
This should get to 2128 without a problem, since Common Lisp has bignums. E.g.:
CL-USER> (print (expt 2 128))
; 340282366920938463463374607431768211456
Powershell, 43 29 bytes
[Numerics.BigInteger]$i=1;for(){$i;$i=$i+1}
Relies on .Net 4.0 and up for System.Numerics.BigInteger
V2
[BigInt]$i=0;for(){($i=$i+1)}
Thanks to TimmyD for the additional tips for use of parens to a automatically produce output and [bigint] for type assignment.
Python 2, 24 bytes
Same method as the Python 3 answer.
i=1
while 1:print i;i+=1
Marbelous, 11450 4632 bytes
Printing decimals is a pain!!
Definitely not winning with this one, but I thought I'd give it a shot. I hope it's ok that it pads the output to 40 zeros (to fit 2^128).
00@0..@1..@2..@3..@4..@5..@6..@7..@8..@9..@A..@B..@C..@D..@E..@F..@G..@H..@I..@J
\\++..00..00..00..00..00..00..00..00..00..00..00..00..00..00..00..00..00..00..00
..EhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhunEhun
....AddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddtAddt
..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7..&7\/
../\&8..........................................................................
....@0..........................................................................
....../\&8......................................................................
....//..@1......................................................................
........../\&8..................................................................
......////..@2..................................................................
............../\&8..............................................................
........//////..@3..............................................................
................../\&8..........................................................
..........////////..@4..........................................................
....................../\&8......................................................
............//////////..@5......................................................
........................../\&8..................................................
..............////////////..@6..................................................
............................../\&8..............................................
................//////////////..@7..............................................
................................../\&8..........................................
..................////////////////..@8..........................................
....................................../\&8......................................
....................//////////////////..@9......................................
........................................../\&8..................................
......................////////////////////..@A..................................
............................................../\&8..............................
........................//////////////////////..@B..............................
................................................../\&8..........................
..........................////////////////////////..@C..........................
....................................................../\&8......................
............................//////////////////////////..@D......................
........................................................../\&8..................
..............................////////////////////////////..@E..................
............................................................../\&8..............
................................//////////////////////////////..@F..............
................................................................../\&8..........
..................................////////////////////////////////..@G..........
....................................................................../\&8......
....................................//////////////////////////////////..@H......
........................................................................../\&8..
......................................////////////////////////////////////..@I..
............................................................................../\&8
........................................//////////////////////////////////////..@J
&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9&9
Sixteenbytedecimalprintermodulewitharegi
:Sixteenbytedecimalprintermodulewitharegi
}J}J}I}I}H}H}G}G}F}F}E}E}D}D}C}C}B}B}A}A}9}9}8}8}7}7}6}6}5}5}4}4}3}3}2}2}1}1}0}00A
/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A/A%A
%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..%A..
+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O..
+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O+O..
:/A
..}0..}0..
..>>}0....
..>>>>\\..
....//..//
../\>>\\..
....>>..//
....>>\\..
....>>....
\\>>//....
..>>......
..>>......
../\......
..../\<<..
......<<..
..\\<<//..
....~~....
....++....
....\\..//
\\....>9\/
..\\..?0..
......++..
....\\....
......{0..
:%A
@0..
}0..
<A-A
{0@0
:Eg
}0}0}0}0}0}0}0}0
^7^6^5^4^3^2^1^0
~~....~~~~..~~~~
^0^0^0^0^0^0^0^0
{0{0{0{0{0{0{0{0
:Ehun
}0..}0
Eg..&0
=8&0{0
&1\/00
0100&0
&1&1{1
{1{0
:Addt
}0}1
{1{1
sed, 116 92 83 bytes
:
/^9*$/s/^/0/
s/.9*$/_&/
h
s/.*_//
y/0123456789/1234567890/
x
s/_.*//
G
s/\n//p
b
Usage: Sed operates on text input and it needs input do anything. To run the script, feed it with just one empty line:
$ echo | sed -f forever.sed
Explanation:
To increment a number, the current number is split up into a prefix and a suffix where the suffix is of the form [^9]9*. Each digit in the suffix is then incremented individually, and the two parts are glued back together. If the current number consists of 9 digits only, a 0 digit is appended, which will immediately incremented to a 1.
VB.NET, 113 99 bytes
Well, pretty straightforward for .NET Framework 4. Needs a reference to System.Numeric.dll:
Module m
Sub Main
Dim i As Numerics.BigInteger
do
i+=1
Console.WriteLine(i)
loop
end sub
End Module
Not exactly original, but hey, even not that much longer than the C# answer ;-)
Thanks Berend for making me dig a little deeper into the compilation process, saving 14 bytes in the process.
Perl, 34 32 30 28 26 23 bytes
-Mbigint -E '{say$_+=1;redo}'
Test with
perl -Mbigint -E '{say$_+=1;redo}'
Go, 104 99 95 bytes
package main
import."math/big"
func main(){a:=&Int{}
for{println(a.Add(a,NewInt(1)).String())}}
Not terribly golfed yet, I might take the time to refine it later.
Note that this will not run on the playground since it runs forever.
Burlesque, 9 bytes
1R@2SH[-Q
If you don't care what the first character is go with 1R@.
Explanation:
R@ is the RangeInf built-in and creates a Block with numbers [N..Infinity] so 1R@ generates a Block {1 2 3 4 5....}.
However, if we display this we'll have a { at the start of our output which we don't want. SH converts a value to a display value (called Pretty) and then back to a String using the display format. 2 is the Format With Spaces so 2SH produces [1 2 3 4 5...]. Now we use [- which is the Tail built-in which removes the first character in that string. Q converts our string to a display value. Burlesque generally prints things
as you input them, so when it prints a String there it will be surrounded by quotes. If one doesn't want that we have to convert it to a display value (called Pretty).
blsq ) "hi"
"hi"
blsq ) "hi"Q
hi
blsq ) 5ro
{1 2 3 4 5}
blsq ) 5ro2SH
"[1 2 3 4 5]"
blsq ) 5ro2SH[-
"1 2 3 4 5]"
blsq ) 5ro2SH[-Q
1 2 3 4 5]
C + gcc extensions, 77 bytes
char c[]={[0 ...49]=48};main(a){for(;;puts(c))for(a=49;++c[a]>57;c[a--]=48);}
O, 7 bytes
1{.o)}w
Explanation:
1 Pushes 1 to the stack
{ }w While the top of the stack is not 0
.o) Output the top of the stack and increment it
Does not work on online IDE, but does in REPL and file.
8086 machine code + DOS, 34 bytes
Hexdump:
30 0D 0A 24 FE C6 BB 00 01 B4 09 CD 21 FE 07 80
3F 3A 75 F2 C6 07 30 4B 3B DA 73 F1 C6 07 30 4A
EB EB
In assembly language:
.MODEL TINY
.CODE
org 100h
MAIN PROC
db '0',13,10,'$' ; output buffer
inc dh ; assign dx=0x100 - address of the output buffer
increase_num:
mov bx, 100h
mov ah, 9
int 21h ; print the number
increase_digit:
inc byte ptr [bx]
cmp byte ptr [bx], '0'+10
jne increase_num
mov byte ptr [bx], '0'
dec bx
cmp bx, dx
jae increase_digit
mov byte ptr [bx], '0'
dec dx
jmp increase_digit
MAIN ENDP
END MAIN
Some explanations:
Output buffer is at offset 0x100; it contains 4 bytes at first: '0', a newline sequence 0d 0a, and '$', which is an end-of-output-buffer byte that DOS uses. These 4 bytes are executed as nonsensical code:
xor [di],cl
or ah,[si]
This destroys the program exit instruction at offset 0, but this is OK because the program will not exit!
The instruction inc dh generates the value 0x100 in dx, which is the address of the output buffer. The output buffer grows down, decreasing the value of dx with each power of 10.
The number is stored as an ASCII string. The increment code starts from the last digit, increases it and checks whether it went out of range 0...9. If yes, it sets the digit to 0 and goes to the next digit (dec bx). If all digits are set to 0, it adds (dec dx) another 0 digit, and immediately increases it to 1.
Ruby, 15 12 bytes
loop{p$.+=1}
p, when given an integer, prints the integer as-is (courtesy of @philomory)$.is a magical variable holding the number of lines read from stdin. It is obviously initialized to 0, and also assignable :)
Intel 8086+ Assembly, 19 bytes
68 00 b8 1f b9 08 00 31 ff f9 83 15 00 47 47 e2 f9 eb f1
Here's a breakdown:
68 00 b8 push 0xb800 # CGA video memory
1f pop ds # data segment
b9 08 00 L1: mov cx, 8 # loop count
31 ff xor di, di # ds:di = address of number
f9 stc # set carry
83 15 00 L2: adc word ptr [di], 0 # add with carry
47 inc di
47 inc di
e2 f9 loop L2
eb f1 jmp L1
It outputs the 128 bit number on the top-left 8 screen positions. Each screen position holds a 8-bit ASCII character and two 4 bit colors.
Note: it wraps around at 2128; simply change the 8 inmov cx, 8 to 9 to show a 144 bit number, or even 80*25 to show numbers up to 232000.
Running
1.44Mb bzip2 compressed, base64 encoded bootable floppy Image
Generate the floppy image by copy-pasting the following
QlpoOTFBWSZTWX9j1uwALTNvecBAAgCgAACAAgAAQAgAQAAAEABgEEggKKAAVDKGgAaZBFSMJgQa
fPsBBBFMciogikZcWgKIIprHJDS9ZFh2kUZ3QgggEEh/i7kinChIP7HrdgA=
into this commandline:
base64 -d | bunzip2 > floppy.img
and run with, for instance, qemu -fda floppy.img -boot a
1.8Mb bootable ISO
This is a base64 encoded bzip2 compressed ISO image. Generate the iso by pasting
QlpoOTFBWSZTWZxLYpUAAMN/2//fp/3WY/+oP//f4LvnjARo5AAQAGkAEBBKoijAApcDbNgWGgqa
mmyQPU0HqGCZDQB6mQ0wTQ0ZADQaAMmTaQBqekyEEwQaFA0AA0AxBoAAA9Q0GgNAGg40NDQ0A0Bi
BoDIAANNAA0AyAAABhFJNIJiPSmnpMQDJpp6nqeo0ZDQaAANB6IA0NAGj1EfIBbtMewRV0acjr8u
b8yz7cCM6gUUEbDKcCdYh4IIu9C6EIBehb8FVUgEtMIAuvACCiO7l2C0KFaFVABcpglEDCLmQqCA
LTCAQ5EgnwJLyfntUzNzcooggr6EnTje1SsFYLFNW/k+2BFABdH4c4vMy1et4ZjYii1FbDgpCcGl
mhZtl6zX+ky2GDOu3anJB0YtOv04YISUQ0JshGzAZ/3kORdb6BkTDZiYdBAoztZA1N3W0LJhITAI
2kSalUBQh60i3flrmBh7xv4TCMEHTIOM8lIurifMNJ2aXr0QUuLDvv6b9HkTQbKYVSohRPsTOGHi
isDdB+cODOsdh31Vy4bZL6mnTAVvQyMO08VoYYcRDC4nUaGGT7rpZy+J6ZxRb1b4lfdhtDmNwuzl
E3bZGU3JTdLNz1uEiRjud6oZ5kAwqwhYDok9xaVgf0m5jV4mmGcEagviVntDZOKGJeLjyY4ounyN
CWXXWpBPcwSfNOKm8yid4CuocONE1mNqbd1NtFQ9z9YLg2cSsGQV5G3EhhMXKLVC2c9qlqwLRlw4
8pp2QkMAMIhSZaSMS4hGb8Bgyrf4LMM5Su9ZnKoqELyQTaMAlqyQ3lzY7i6kjaGsHyAndc4iKVym
SEMxZGG8xOOOBmtNNiLOFECKHzEU2hJF7GERK8QuCekBUBdCCVx4SDO0x/vxSNk8gKrZg/o7UQ33
Fg0ad37mh/buZAbhiCIAeeDwUYjrZGV0GECBAr4QVYaP0PxP1TQZJjwT/EynlkfyKI6MWK/Gxf3H
V2MdlUQAWgx9z/i7kinChITiWxSo
into
base64 -d bunzip2 > cdrom.iso
and configure a virtual machine to boot from it.
DOS .COM
This is a base64 encoded DOS .COM executable:
aAC4H7kIADH/+YMVAEdH4vnr8Q==
Generate a .COM file using
/bin/echo -n aAC4H7kIADH/+YMVAEdH4vnr8Q== | base64 -d > COUNTUP.COM
and run it in (Free)DOS.
Perl 6, 13 bytes
.say for 1..*
C++, 104 bytes
#include<cstdio>
int a,c[50]={-38};int main(){for(a=49;++c[a]>9;c[a--]=0);for(b:c)putchar(b+48);main();}
A translation of my C answer. This uses a terse range-based for loop, which is a C++1z feature briefly added to some compilers but later voted out of C++17. clang++ 3.5.2 compiles my code fine, but I'm not sure if it counts as "C++". I can change it to for(int b:c) if it's deemed invalid.
C, 95 bytes
int a,c[50]={-38};main(){for(a=49;++c[a]>9;c[a--]=0);for(a=0;a<50;++a)putchar(c[a]+48);main();}
Prints:
00000000000000000000000000000000000000000000000001
00000000000000000000000000000000000000000000000002
...
Ceylon (on JVM), 92 87 78 bytes
(The Big integer type Whole which is used here does only exist on the JVM, not when compiling for JavaScript.)
This is the third improvement (78 bytes):
import ceylon.math.whole{o=one}shared void run(){loop(o)(o.plus).each(print);}
The loop function is a functional version of the while-statement – it creates a stream from a starting value (one) and a function (one.plus), applying the function to the previous value until it returns finished (which our function never does, so it becomes an infinite stream). On each element, print(...) is applied.
An Integer version which goes only until just under 2^63 (on JVM) or 2^31 (on JS), then will wrap around to negatives (JVM) or stall (for JS), for 48 bytes:
shared void run(){loop(1)(1.plus).each(print);}
Second version (87):
import ceylon.math.whole{o=one}shared void run(){{o}.cycled.scan(o)(plus).each(print);}
That builds first an infinite stream of ones, and then creates a scanning stream, which calculates the partial sums (which then are each printed).
Original version (92):
A straight-forward n++-loop, with a big integer type (called Whole in Ceylon, but the type name is not actually used in this program, just the name of the 1):
import ceylon.math.whole{o=one}shared void run(){variable value n=o;while(0<1){print(n++);}}
This one is shorter (83), counting from 1 to 2^65536, but it doesn't actually work:
import ceylon.math.whole{o=one,t=two}shared void run(){(o..t^t^t^t^t).each(print);}
The problem is that the range notation x..y will call span(x,y), which will call x.offset(y) to get the offset between them, and this method is defined to return an Integer – which will overflow here, as the difference is much too large to fit into an Integer (which was the whole point of using Whole here).
Scala, 41 39 35 bytes
Stream.iterate(BigInt(0)){_+1}print
Other versions (I left all solutions there because they're significantly different):
def r(n:BigInt){println(n);r(n+1)};r(0) // 39
var i=BigInt(0);while(1>0)println{i+=1;i} // 41
This is my first time writing Scala code.
Original idea based on SuperJedi224's Java answer.
{i=>i+1} can be shortened to {_+1}.
foreach println was replaced with print because the problem description allows any separator.
Iterator.iterate and Stream.iterate, though completely different, do the same thing.
Other tries
Stream.from(0).print() // overflows at Integer.MAX_VALUE
BigInt(0).to(10)foreach println // 10 should be BigInt.MAX_VALUE (=Infinity), which doesn't exist
def from(start:BigInt):Stream[BigInt]=Stream.cons(start,from(start+1));from(0).print // too long
Hexagony, 12 11 10 7 bytes
Thanks to alephalpha for fitting the code into side-length 2.
10})!';
Unfolded:
1 0
} ) !
' ;
This one is fairly simple. 10 writes a 10, i.e. a linefeed to the initial memory edge. Then })!'; is repeatedly executed in a loop:
}move to the next memory edge.)increment it.!print it as an integer.'move back to the 10.;print it as a character.
I believe that this is optimal (although by far not unique). I've let the brute force script I wrote for this answer search for 6-byte solutions under the assumption that it would have to contain at least one each of ; and ! and either ( or ), and would not contain ?, , or @, and it didn't find any solutions.
Julia, 35 bytes
i=big(0);while 1>0 println(i+=1)end
This uses Julia's GMP-based arbitrary precision integers.
C++, 146 141 138 bytes
Using a standard bigint library is perhaps the most boring way of answering this question, but someone had to do it.
#include<stdio.h>
#include<boost/multiprecision/cpp_int.hpp>
int main(){for(boost::multiprecision::uint512_t i=1;;){printf("%u\n",i++);}}
Ungolfed:
#include<cstdio>
#include<boost/multiprecision/cpp_int.hpp>
int main()
{
for(boost::multiprecision::uint512_t i=1;;)
{
std::printf("%u\n", i++);
}
}
The reason the golfed version uses stdio.h and not cstdio is to avoid having to use the std:: namespace.
This is my first time golfing in C++, let me know if there's any tricks to shorten this further.
Win32 x86 Machine Code (PE32 Executable), 933 bytes
This implements a virtual datatype using a lookup table (aka array). The challenge requests support for 2^128 which is 39 decimal digits. By accident, this solution supports 38+N digit numbers, where N is the width of word (i.e. two bytes). After that, the behavior is undefined. You might notice a whole lot of too simple or too redundant code in the assembly below, but this is intended, because the compression algorithm optimizes this.
For example,
mov EAX, 0
mov dword [@@DATA+164], EAX
is two bytes shorter than
mov dword [@@DATA+164], 0
Also: I though of using the C runtime library (MSVCRT) to convert numbers to strings, but this is a DIY approach, so this solution contains it's own method of converting numbers to strings. Without this, the byte count would be 800-ish. Keep in mind that the PE header and decompression take up about 697 bytes :). Also, this is Win32 code (fully debugged, shouldn't produce any errors and spawns a clean console context to run in), it is not "just using Interrupts", so this contains it's own string printing method.
I've used MEW11SE to crunch the executable, because MEW's LZMA-E9 routine beats UPX, mpress, kkrunchy etc. 9.9 out of 10 times by far. I could have used nasm and crinkler, but I hate both of them. The assembly below is fasm.
Here's a binary (compressed) - Here's another binary (uncompressed)
Disclaimer: The compressed binary will probably set your PC on fire if you happen to have an AV installed.
Assembly
; minxomat
; Link as CUI subsystem
format PE CONSOLE
section ".code" code readable executable
; Convert single digit unsigned word to null-terminated char
makestr:
push EBP
mov EBP, ESP
sub ESP, 12
mov EAX, @@TEXT+0
mov dword [EBP-4], EAX
mov EAX, @@TEXT+3
mov dword [EBP-8], EAX
mov EAX, 0
mov dword [EBP-12], EAX
mov EAX, dword [EBP+8]
add EAX, dword [EBP-8]
mov AL, byte [EAX+0]
mov EBX, dword [EBP-12]
add EBX, dword [EBP-4]
mov byte [EBX+0], AL
mov AL, 0
push EAX
mov EAX, dword [EBP-12]
add EAX, 1
add EAX, dword [EBP-4]
pop EBX
mov byte [EAX+0], BL
mov EAX, dword [EBP-4]
mov ESP, EBP
pop EBP
ret 4
; Ouput null-term'ed string at this pointer to console
printme:
push EBP
mov EBP, ESP
sub ESP, 4
mov EAX, 0
mov dword [EBP-4], EAX
addone:
mov EAX, dword [EBP-4]
add EAX, dword [EBP+8]
mov AL, byte [EAX+0]
cmp AL, 0
je fwd
inc dword [EBP-4]
jmp addone
fwd:
xor EAX, EAX
push EAX
lea EAX, [EBP-4]
push EAX
mov EAX, dword [EBP-4]
push EAX
mov EAX, dword [EBP+8]
push EAX
mov EAX, 4294967285
push EAX
call [@10024]
push EAX
call [@10025]
mov ESP, EBP
pop EBP
ret 4
; Entry point.
main:
; Print initial zero
push EBP
mov EBP, ESP
mov EAX, @@TEXT+14
push EAX
call printme
@10007:
mov EAX, 1
mov dword [@@DATA+160], EAX
mov dword [@@DATA+164], EAX
mov EAX, 38
mov dword [@@DATA+156], EAX
@10008:
mov EAX, dword [@@DATA+156]
cmp EAX, 0
jle @10016
@10009:
mov EAX, dword [@@DATA+156]
shl EAX, 2
mov EAX, dword [@@DATA+EAX+0]
mov EBX, dword [@@DATA+160]
add EAX, EBX
mov EBX, dword [@@DATA+156]
shl EBX, 2
mov dword [@@DATA+EBX+0], EAX
mov EAX, dword [@@DATA+156]
shl EAX, 2
mov EAX, dword [@@DATA+EAX+0]
cmp EAX, 9
jle @10011
@10010:
mov EAX, 0
mov EBX, dword [@@DATA+156]
shl EBX, 2
mov dword [@@DATA+EBX+0], EAX
mov EAX, 1
mov dword [@@DATA+160], EAX
jmp @10014
@10011:
mov EAX, 0
mov dword [@@DATA+160], EAX
@10014:
dec dword [@@DATA+156]
jmp @10008
@10016:
mov EAX, dword [@@DATA+156]
cmp EAX, 39
jge @10022
@10017:
mov EAX, dword [@@DATA+156]
shl EAX, 2
mov EAX, dword [@@DATA+EAX+0]
cmp EAX, 0
jg @10019
@10018:
mov EAX, dword [@@DATA+164]
cmp EAX, 0
jne @10021
@10019:
mov EAX, dword [@@DATA+156]
shl EAX, 2
mov EAX, dword [@@DATA+EAX+0]
push EAX
call makestr
push EAX
call printme
mov EAX, 0
mov dword [@@DATA+164], EAX
@10021:
inc dword [@@DATA+156]
jmp @10016
@10022:
mov EAX, @@TEXT+17
push EAX
call printme
jmp @10007
section ".data" data readable writeable
@@TEXT db "00", 0
db "0123456789", 0
db "0", 10, 0
db 10, 0
@@DATA rb 168
section ".idata" import data readable writeable
dd 0, 0, 0, RVA @10026, RVA @10024
dd 0, 0, 0, 0, 0
@10024 dd RVA @10027
@10025 dd RVA @10028
dd 0
@10026: db "KERNEL32.DLL", 0
@10027: dw 0
db "GetStdHandle", 0
@10028: dw 0
db "WriteFile", 0
section ".reloc" fixups data readable discardable
entry main
Hexdump
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 4D 5A 6B 65 72 6E 65 6C 33 32 2E 64 6C 6C 00 00 MZkernel32.dll..
00000010 50 45 00 00 4C 01 02 00 00 00 00 00 00 00 00 00 PE..L...........
00000020 00 00 00 00 E0 00 0F 01 0B 01 00 00 00 02 00 00 ....à...........
00000030 00 00 00 00 00 00 00 00 95 51 00 00 10 00 00 00 ........•Q......
00000040 00 10 00 00 00 00 40 00 00 10 00 00 00 02 00 00 ......@.........
00000050 04 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ................
00000060 00 60 00 00 00 02 00 00 00 00 00 00 03 00 00 00 .`..............
00000070 00 10 00 00 00 10 00 00 00 00 01 00 00 00 00 00 ................
00000080 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ................
00000090 91 51 00 00 14 00 00 00 00 00 00 00 00 00 00 00 ‘Q..............
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000100 00 00 00 00 00 00 00 00 4D 45 57 00 46 12 D2 C3 ........MEW.F.ÒÃ
00000110 00 40 00 00 00 10 00 00 00 00 00 00 00 00 00 00 .@..............
00000120 00 00 00 00 00 00 00 00 00 00 00 00 E0 00 00 C0 ............à..À
00000130 02 D2 75 DB 8A 16 EB D4 00 10 00 00 00 50 00 00 .ÒuÛŠ.ëÔ.....P..
00000140 A5 01 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ¥...............
00000150 00 00 00 00 E0 00 00 C0 BE 1C 50 40 00 8B DE AD ....à..À¾.P@.‹Þ.
00000160 AD 50 AD 97 B2 80 A4 B6 80 FF 13 73 F9 33 C9 FF .P.—²€¤¶€ÿ.sù3Éÿ
00000170 13 73 16 33 C0 FF 13 73 21 B6 80 41 B0 10 FF 13 .s.3Àÿ.s!¶€A°.ÿ.
00000180 12 C0 73 FA 75 3E AA EB E0 E8 72 4E 00 00 02 F6 .Àsúu>ªëàèrN...ö
00000190 83 D9 01 75 0E FF 53 FC EB 26 AC D1 E8 74 2F 13 ƒÙ.u.ÿSüë&¬Ñèt/.
000001A0 C9 EB 1A 91 48 C1 E0 08 AC FF 53 FC 3D 00 7D 00 Éë.‘HÁà.¬ÿSü=.}.
000001B0 00 73 0A 80 FC 05 73 06 83 F8 7F 77 02 41 41 95 .s.€ü.s.ƒø.w.AA•
000001C0 8B C5 B6 00 56 8B F7 2B F0 F3 A4 5E EB 9B AD 85 ‹Å¶.V‹÷+ðó¤^ë›.…
000001D0 C0 75 90 AD 96 AD 97 56 AC 3C 00 75 FB FF 53 F0 Àu..–.—V¬<.uûÿSð
000001E0 95 56 AD 0F C8 40 59 74 EC 79 07 AC 3C 00 75 FB •V..È@Ytìy.¬<.uû
000001F0 91 40 50 55 FF 53 F4 AB 75 E7 C3 00 00 00 00 00 ‘@PUÿSô«uçÃ.....
00000200 33 C9 41 FF 13 13 C9 FF 13 72 F8 C3 66 51 00 00 3ÉAÿ..Éÿ.røÃfQ..
00000210 73 51 00 00 00 00 00 00 00 50 40 00 30 01 40 00 sQ.......P@.0.@.
00000220 8D 10 40 00 00 10 40 00 55 03 89 E5 83 EC 0C B8 ..@...@.U.‰åƒì.¸
00000230 81 20 40 C3 D1 45 FC E1 03 53 08 F8 70 20 E1 11 . @ÃÑEüá.S.øp á.
00000240 F4 8B EC 08 03 CE 1C 8A 1E 1E 5D FC 73 3E FC 88 ô‹ì..Î.Š..]üs>üˆ
00000250 38 B0 37 50 26 B1 83 C0 01 BF 2C 3F 5B B7 18 18 8°7P&±ƒÀ.¿,?[·..
00000260 60 89 EC 5D C2 70 04 AB 46 BD 33 36 FC 66 2F 40 `‰ì]Âp.«F½36üf/@
00000270 08 6C 70 3C 18 74 05 FF 18 EB EF 0D 31 C0 50 8D .lp<.t.ÿ.ëï.1ÀP.
00000280 10 A2 76 04 7C 08 1B B8 F5 FF 02 F7 41 15 28 30 .¢v.|..¸õÿ.÷A.(0
00000290 B2 DA 0F 2C 28 47 E2 B8 0E A1 82 50 E8 AB BD 45 ²Ú.,(Gâ¸.¡‚P諽E
000002A0 B1 01 9F A3 B3 BA 21 B7 B7 0B F5 26 08 0F AF 94 ±.Ÿ£³º!··.õ&..¯”
000002B0 A1 05 1C 83 F8 0A 7E 6A 0A 80 C1 E0 02 8B 80 13 ¡..ƒø.~j.€Áà.‹€.
000002C0 DD 13 94 1D 2D 1A 01 D8 10 20 17 E3 02 89 83 84 Ý.”.-..Ø. .ã.‰ƒ„
000002D0 8D 25 31 70 09 7E DE 9A AA 36 27 85 6F 0D EB 0A .%1p.~Þšª6'…o.ë.
000002E0 40 18 0C FF 50 0D 25 EB 53 8C 74 0A 27 7D 49 4F @..ÿP.%ëSŒt.'}IO
000002F0 F3 80 7F 0A A1 52 B7 0A 15 75 24 1D A4 04 C8 9D ó€..¡R·..u$.¤.È.
00000300 FE 19 0C DD 14 22 53 B7 11 05 0C AD 2A B8 11 23 þ..Ý."S·....*¸.#
00000310 44 C0 E9 55 10 F0 80 00 00 20 40 00 30 E3 C3 98 DÀéU.ð€.. @.0ãØ
00000320 31 32 33 03 34 35 36 37 38 39 38 16 0A 72 C0 00 123.4567898..rÀ.
00000330 D1 4F 40 00 28 38 30 40 07 4B 45 52 4E 30 4C 33 ÑO@.(80@.KERN0L3
00000340 32 2E 75 44 ED C0 80 47 1C 65 74 53 83 64 48 61 2.uDíÀ€G.etSƒdHa
00000350 6E A3 6C D6 1C 1F 57 72 69 FB BA 46 51 0B 80 00 n£lÖ..WriûºFQ.€.
00000360 00 00 00 00 D1 4F 40 00 4C 6F 61 64 4C 69 62 72 ....ÑO@.LoadLibr
00000370 61 72 79 41 00 47 65 74 50 72 6F 63 41 64 64 72 aryA.GetProcAddr
00000380 65 73 73 00 00 00 00 00 00 00 00 00 00 00 00 00 ess.............
00000390 00 0C 50 00 00 E9 BE AF FF FF 00 00 00 02 00 00 ..P..龯ÿÿ......
000003A0 00 0C 50 00 00 ..P..
Racket, 40 bytes
(sequence-for-each println(in-naturals))
Racket has arbitrary-precision numbers, so this will continue to count up forever.
GolfScript, 9 bytes
1{.p).}do
1 # push 1
{ # loop
.p # duplicate, output
). # increment, duplicate
}do # while non-zero
PHP, 31 bytes
<?for(;;)echo$i=bcadd($i,1),~õ;
I assume default settings, as they are without an .ini (you may disable your local .ini with the -n option).
Sample Usage
$ php -n countup.php
Minkolang, 4 bytes
1+dN
Try it here. (Well, actually, be careful. 3 seconds of run time was enough to get up to ~40,000.)
1+ adds 1 to the top of stack, d duplicates it, and N outputs the top of stack as an integer with a trailing space. This loops because Minkolang is toroidal, so when the program counter goes off the right edge, it reappears on the left.
Acc!, 64 65 bytes
Also works in Acc!!.
Count q while 1 {
Count x while q-x+1 {
Write 7
}
Write 9
}
This prints the numbers out in unary using Bell characters seperated by tabs. If I have to use a more standard character, that would make the program 66 bytes.
The Acc! interpreter provided in the linked answer translates Acc! to Python, which does support arbritrary-precision integers.
Foo, 6 bytes
(+1$i)
Explanation
( ) Loop
+1 Add one to current element
$i Output current element as a decimal integer
Kotlin, 102 bytes
import java.math.BigInteger.*fun main(a:Array<String>){var i=ZERO;while(1>0){i=i.add(ONE);println(i)}}
Based on SuperJedi224's Java answer.
Processing, 95 85 71 bytes
java.math.BigInteger i;{i=i.ZERO;}void draw(){println(i=i.add(i.ONE));}
I tried something with a while loop but it causes all of Processing to crash, so I'll stick with this for now.
(Thanks to @SuperJedi224 and @TWiStErRob for suggestions.)
Java, 139 138 127 123 bytes
class K{public static void main(String[]a){java.math.BigInteger b=null;for(b=b.ZERO;;)System.out.println(b=b.add(b.ONE));}}
C, 89 bytes
A new approach (implementing a bitwise incrementer) in C:
b[999],c,i;main(){for(;;)for(i=c=0,puts(b);i++<998;)putchar(48+(c?b[i]:(b[i]=c=!b[i])));}
Less golfed
int b[999], c, i;
main() {
for(;;)
for(i=c=0, puts(b); i++ < 998;)
putchar(48 + (c ? b[i] : (b[i] = c = !b[i])));
}
Terminate
This version has the slight flaw, that it does not terminate (which isn't a requirement at the moment). To do this you would have to add 3 characters:
b[129],c=1,i;main(){for(;c;)for(i=c=0,puts(b);i++<128;)putchar(48+(c?b[i]:(b[i]=c=!b[i])));}
Rotor, 7 bytes
1{1+}|
There's an unprintable again, hexdump:
0000000: 317b 1b31 2b7d 7c 1{.1+}|
ew 7 bytes
Python 2 VM Opcodes, 14 bytes?
LOAD_CONST 0
LOAD_CONST 1
INPLACE_ADD
DUP_TOP
PRINT_ITEM
JUMP_ABSOLUTE 2
I'm not sure how to score this, the compiled code is 12 bytes of vm code but there are also the constants, which would be unscored. Each constant can fit in a single bit but I'll count them as 1 byte each for now.
The compiled .pyc file is 106 bytes long(!) and the raw text is 111 bytes long.
I will probably just write a short script that just takes python opcodes and runs them properly (A bit like Pyth but much more low level).
Overall, it's a very simple program. It loads 0 and 1 onto the stack and adds them. This removes both from the stack and leaves it with the result. It then duplicates the stack and prints the value of the first item, removing it from the stack. It then goes to line 2.
.pyc file (hexdump)
03 F3 0D 0A DB 5B 47 56 63 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 73 0C 00 00 00 64 01 00 64 02 00 37 04 47 71 03 00 28 03 00 00 00 4E 69 00 00 00 00 69 01 00 00 00 28 00 00 00 00 28 00 00 00 00 28 00 00 00 00 28 00 00 00 00 74 09 00 00 00 70 79 6B 65 5F 63 6F 64 65 52 00 00 00 00 01 00 00 00 74 00 00 00 00
Befunge, 4 bytes
1+:.
This just requires an interpreter with arbitrary precision integers.
Matlab, 132 bytes
a=0;while 1;b=a==9;n=find(cumsum(b)-(1:numel(b)),1);a(n)=a(n)+1;a(1:n-1)=0;if ~numel(n);a=[0*a,1];end;disp([a(end:-1:1)+'0','']);end
Ok, I think this is the first serious answer that accomplishes this task without a trivial builtin abitrary size integer. This program implements an arbitrary size integer as an array of integers. Each integer is always between 0 and 9, so each array element represents one decimal digit. The array size wil be increased by one as soon as we are at e.g. 999. The memory size is no problem here, as 2^128 only requires an array of length 39.
a=0;
while 1
b=a==9;
%first number that is not maxed out
n=find(cumsum(b)-(1:numel(b)),1);
%increase that number, and sett all maxed out numbers to zero
a(n)=a(n)+1;
a(1:n-1)=0;
if ~numel(n) %if we maxed out all entries, add another digit
a=[0*a,1];
end
disp([a(end:-1:1)+'0',''])%print all digits
end
><>, 8 bytes
01+:nao!
Steps:
- Push 0 on the stack
- Add 1 to the top stack element
- Duplicate top stack element
- Output the top of the stack as number
- Output a newline
- Go to step 2 by wrapping around and jumping the next instruction (step 11)
(A less memory efficient (hence invalid) program is llnao.)
C, 93
Count up to 10^97. Add 3 bytes to count up to 10^997 (and so on).
char*p,d[99],*q=d+97;main(){while(p-d)*q>56?(*q--=48):(*q||(*(p=q)=48),++*q,puts(p),q=d+97);}
Less golfed
char*p,d[99],*q=d+97;
main()
{
while(p!=d)
{
if(*q > '8') {
*q = '0';
--q;
}
else {
if (!*q) {
*q = '0';
p = q;
}
++*q;
puts(p);
q = d + 97;
}
}
}
CJam, 7 bytes
0{)_p}h
Explanation:
0 e# Push a zero to the stack
{ e# Start a block
) e# Increment top of stack
_ e# Duplicate top of stack
p e# Print top of stack
} e# End block
h e# Do-while loop that leaves the condition on the stack
Note: Must use Java interpreter.
C (64-bit architecture only), 53 bytes
Relies on pointers being at least 64 bits and prints them in hex using the %p specifier. The program would return right when it hits 2^128.
char*a,*b;main(){for(;++b||++a;)printf("%p%p ",a,b);}
Gol><>, 3 bytes
P:N
Steps:
- Add 1 to the top stack element (at start it is an implicit 0)
- Duplicate top stack element
- Pop and output the top of the stack as number and a newline
- Wrap around to step 1 as we reached the end of the line
Labyrinth, 5 bytes
):
\!
♫ The IP in the code goes round and round ♫
Relevant instructions:
) Increment top of stack (stack has infinite zeroes at bottom)
: Duplicate top of stack
! Output top of stack
\ Output newline
Pyth, 4 bytes
.V1b
Explanation:
.V1 for b in range(1 to infinity):
b print b
