# Count up forever

Write a program that counts up forever, starting from one.

Rules:

• Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.
• Your program must be a full, runnable program, and not a function or snippet.
• Your program must output each number with a separating character in between (a newline, space, tab or comma), but this must be consistent for all numbers.
• You may print the numbers in decimal, in unary or in base 256 where each digit is represented by a byte value.
• Your program must count at least as far as 2128 (inclusive) without problems and without running out of memory on a reasonable desktop PC. In particular, this means if you're using unary, you cannot store a unary representation of the current number in memory.
• Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

• This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

### Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

## Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes


<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 63834; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 39069; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "//api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "//api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(42), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

• I'm not sure how to combine must output each number with a separating character in between with may print the numbers [...] in base 256. – Dennis Nov 14 '15 at 14:25
• For future challenges, may I recommend the sandbox such that all these details could be sorted out before people start posting answers? :) – Martin Ender Nov 14 '15 at 14:32
• @IlmariKaronen I interpret that as being a memory limit, not a time limit. possibly a time limit on per-increment. just set the counter to 2**128-10 and see how long it takes to take those last ten steps. – Sparr Nov 15 '15 at 7:41
• Can we have leading zeroes in the output? – Paŭlo Ebermann Nov 15 '15 at 11:43
• Ugh!!! I have an answer for TI-89 (56b), but I can't post b/c I'm new to the site and don't have Rep 10+! – gregsdennis Nov 15 '15 at 20:45

## 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

• The program is sad that its not stopping.. – Optimizer Nov 14 '15 at 17:10
• @Optimizer def sad( indeed ): – yyny Nov 16 '15 at 18:11
• Why is this not 4 bytes? – Aurel Bílý Dec 30 '15 at 11:17
• @Aurel300 The fifth byte is the newline between : and \ – Sp3000 Dec 30 '15 at 12:10
• @Sp3000 Ah, yes. Silly me. :) – Aurel Bílý Dec 30 '15 at 15:04

# ><>, 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.)

• +1 for the impatient upvote-demanding implicit in a line of code that basically reads “plus one, now!”. – Janus Bahs Jacquet Nov 14 '15 at 14:39

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

• Isn't there a symbol that generalizes map/mapM etc? – JDługosz Nov 16 '15 at 2:41
• @JDługosz: not that I know – Bergi Nov 16 '15 at 3:09
• Ah, 'cause it would still have to sequence the result to get the output to really happen. – JDługosz Nov 16 '15 at 3:27
• isnt simply [1..] allowed, since it prints all numbers with a comma in beween? or the first [ screw it all up? – Baconaro Dec 30 '15 at 11:06
• With leading [ allowed you could say main=print[1..] – Christian Sievers Jul 23 '16 at 12:36

# 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);}

• Invalid as it can't count up to 2^128 – edc65 Nov 14 '15 at 14:52
• @edc65 The spec says until 2^128, which is not inclusive. – feersum Nov 14 '15 at 15:05
• I like CodeGolf when it is about expressing and rewarding creativity. feersum is clearly not competing for the win here. To see many downvotes on a technicality and to modify the wording of the question to make sure his answer is in violation makes me sad. – flodel Nov 14 '15 at 17:44
• I thought the words "at least as far as 2^128" were clear enough... – vrwim Nov 14 '15 at 18:00
• @vrwim You didn't write that. You wrote "until 2^128". SuperJedi edited it a few minutes ago. – feersum Nov 14 '15 at 18:07

# 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

# 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
..&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

}0}1
{1{1

• Would printing binary be any shorter? – SuperJedi224 Nov 14 '15 at 20:15
• (or what about unary?) – Doorknob Nov 14 '15 at 21:58
• @Doorknob displaying the output isn't the problem. It's something on the Ehun board that is supposed to increment the next digit, but doesn't work properly – TheDoctor Nov 14 '15 at 21:59
• Did you know you can leave out the periods at the end of every line and blank lines between boards and use single characters for board names? You just have to repeat that single character the appropriate amount of time to call upon it. This can get your answer down to about 3000 bytes. – overactor Dec 30 '15 at 8:53
• Eventually I'm going to push a commit to marbelous.py that includes all of include/ by default – Sparr Feb 6 '19 at 2:55

## Hexagony, 121110 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.

# bc, 10

for(;;)++i


Unusual that bc is shorter than dc.

From man bc:

DESCRIPTION

bc is a language that supports arbitrary precision numbers

• Where does this print it out? – Bálint Apr 24 '16 at 7:47
• @Bálint ++i is an expression, but not an assignment, and is therefor explicitly output. Did you try running it? echo 'for(;;)++i' | bc in your nearest Linux terminal. – Digital Trauma Apr 24 '16 at 7:52
• I don't have a single Linux terminal in my house. I was just curious. – Bálint Apr 24 '16 at 8:04
• @Bálint Every house should have a Linux terminal. – Digital Trauma Apr 24 '16 at 8:09
• @Bálint Running this program is your use ;) – Insane Apr 24 '16 at 18:32

# Pyth, 4 bytes

.V1b


### Explanation:

.V1    for b in range(1 to infinity):
b      print b

• f!\n (TIO link) will work for 3 bytes, not sure if that's using any features that have been added after your answer though. – Sok Jul 12 '19 at 14:03
• @Sok Clever. However, I won't change the answer because I think that f was a feature oft Pyth 4 years ago. – Jakube Jul 12 '19 at 15:23
• I thought so too, which is why I left it as a comment - new language features to beat an older answer always feel cheap IMO – Sok Jul 12 '19 at 16:51

# Java, 139138127 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));}}

• A smaller infinite loop in java is for(;;) for an easy 3 bytes. – ankh-morpork Nov 14 '15 at 17:29
• You can also save another 2 with BigInteger b=null;b=b.ZERO;, sadly the =null is needed, even thought it's a static access. – TWiStErRob Nov 14 '15 at 19:46
• And then another 9, because you can get rid of the import by referencing BigInteger by FQCN only once. – TWiStErRob Nov 14 '15 at 19:47
• @TWiStErRob Somehow, I hadn't realized that would be shorter. – SuperJedi224 Nov 14 '15 at 20:05
• For Java 8 or newer, you can replace the class with interface and remove public from the function. Don't wanna copy your code and post it as a new answer. – Luca H Nov 24 '17 at 6:55

# Mathematica, 22 bytes

i=0;While[Echo[++i]>0]


Echo is a new function in Mathematica 10.3.

• Echo gives four separating characters: newline plus ">> ". Not sure this is valid – maybe use Print instead? Also, save a byte with i=0;While[Echo@++i>0]. – Roman Jul 14 '19 at 18:08

# 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

• 1 is a truthy value in Python (and most other languages). So while 1: is enough. – Jakube Nov 14 '15 at 12:49
• Also, you can put the whole while on one line – Sp3000 Nov 14 '15 at 12:51
• You can save a byte by using repr(k) rather than print(k). Also, I count your byte size as 25 (without my suggested change) – wnnmaw Nov 16 '15 at 21:00
• You can not use repr instead of print. repr does not output anything. @wnnmaw – Zach Gates Nov 17 '15 at 19:47
• What does repr do then? – flawr Nov 17 '15 at 19:52

# 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 :)
• @philomory It is typically suggested for users to leave a comment suggesting their byte-saving solution. Also, I'd like to see an explanation for this one. c: – Addison Crump Nov 15 '15 at 20:26

# Microsoft PowerPoint (33 Slides, 512 shapes to meet minimum requirements)

## 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.

• Note: sadly as of the time I write this, this does not work with LibreOffice, as there seems to be a bug where things that appear don't stay that way. – Calculuswhiz Jan 15 '20 at 3:05

# 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


# Processing, 9585 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.)

• What's with the spaces? I'm pretty sure import java.math.*;BigInteger i=BigInteger.ZERO;void draw(){println(i=i.add(BigInteger.ONE));} will work. – SuperJedi224 Nov 14 '15 at 15:55
• Yeah, just fixed that. – geokavel Nov 14 '15 at 15:56
• Does Processing allow the BigInteger.ONE to be changed toi.ONE? – SuperJedi224 Nov 14 '15 at 16:05
• @SuperJedi224 Yes, it does. Thanks! – geokavel Nov 14 '15 at 16:16
• Alright, have an upvote. – SuperJedi224 Nov 14 '15 at 16:28

# 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.

• Doesn't a list print all its contents at once? If this list is infinite, then it cannot possibly fit in memory or on your screen, and it will never stop being generated, so it will never be printed. – cat Dec 29 '15 at 15:58
• @cat Samau is written in Haskell, and it's lazy. It won't generate the whole list before printing it. – alephalpha Dec 30 '15 at 2:48
• Just a heads up. On the GitHub page for Samau, in the description of @, "push" is misspelt. – Carcigenicate Mar 31 '17 at 22:39
• @Carcigenicate Thank you. – alephalpha Apr 1 '17 at 4:10

# JavaScript (ES6), 9994 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.

• This is why I have a pop-up blocker. – Comintern Nov 14 '15 at 16:47
• just saying: for(i=0;;)alert(i++) I don't think you need all of those controls – towc Dec 30 '15 at 13:47
• @towc That won't work. All numbers are 64 bit floats in JavaScript which have a maximum safe integer value of 2^53 but the question requires it to go up to 2^128. – user81655 Dec 30 '15 at 13:53
• oh, fair point... – towc Dec 30 '15 at 14:00
• this is simpler: (function x(e){alert(e);x(++i)}(i=0)) (37 bytes) – derder56 Aug 18 '20 at 0:09

## C++, 146141 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.

• Maybe you could use '\n' instead of std::endl, would save you 8 bytes. Also there may be a way to use CPP #define to compress some repetition, – Kenney Nov 15 '15 at 2:23
• @Kenney Thank you for that! (It only saves 5 bytes, not 8.) I think I may have come up with a way to tweak that section even shorter, though. – felixphew Nov 15 '15 at 3:50
• I do not knoww boost (and I would not say it is standard either) but isn't i defaultly constructed with the value of 0? You could then strip off definition and switch postincrement to preincremet which would save 2b – Zereges Nov 22 '15 at 20:52
• How about the deprecated #import? – connectyourcharger Jul 3 '19 at 20:35

## 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
BoDIAANNAA0AyAAABhFJNIJiPSmnpMQDJpp6nqeo0ZDQaAANB6IA0NAGj1EfIBbtMewRV0acjr8u
b8yz7cCM6gUUEbDKcCdYh4IIu9C6EIBehb8FVUgEtMIAuvACCiO7l2C0KFaFVABcpglEDCLmQqCA
LTCAQ5EgnwJLyfntUzNzcooggr6EnTje1SsFYLFNW/k+2BFABdH4c4vMy1et4ZjYii1FbDgpCcGl
mhZtl6zX+ky2GDOu3anJB0YtOv04YISUQ0JshGzAZ/3kORdb6BkTDZiYdBAoztZA1N3W0LJhITAI
2kSalUBQh60i3flrmBh7xv4TCMEHTIOM8lIurifMNJ2aXr0QUuLDvv6b9HkTQbKYVSohRPsTOGHi
isDdB+cODOsdh31Vy4bZL6mnTAVvQyMO08VoYYcRDC4nUaGGT7rpZy+J6ZxRb1b4lfdhtDmNwuzl
E3bZGU3JTdLNz1uEiRjud6oZ5kAwqwhYDok9xaVgf0m5jV4mmGcEagviVntDZOKGJeLjyY4ounyN
CWXXWpBPcwSfNOKm8yid4CuocONE1mNqbd1NtFQ9z9YLg2cSsGQV5G3EhhMXKLVC2c9qlqwLRlw4
8pp2QkMAMIhSZaSMS4hGb8Bgyrf4LMM5Su9ZnKoqELyQTaMAlqyQ3lzY7i6kjaGsHyAndc4iKVym
SEMxZGG8xOOOBmtNNiLOFECKHzEU2hJF7GERK8QuCekBUBdCCVx4SDO0x/vxSNk8gKrZg/o7UQ33
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.

## 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.

• I know, this a very old answer, but unfortunately, it doesn't work. First of all, OP asked to start from 1, not from 0 as range does. Moreover, since map is lazy, this doesn't produce any results at all, as nothing forces to realize the collection. – Kirill L. Feb 26 at 15:19
• Yup that's true :) – MONODA43 Feb 26 at 15:21

## C# .NET 4.0, 111103102 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

• You can save 8 bytes with class C{static void Main(){var b=System.Numerics.BigInteger.One;for(;;)System.Console.WriteLine(b++);}} :~)! – sweerpotato Nov 15 '15 at 11:16
• Move declaration of b and Console.WriteLine into the loop structure: class C{static void Main(){for(var b=System.Numerics.BigInteger.One;;Console.WriteLine(b++));}} – Kvam Nov 15 '15 at 12:09
• You still need System. That saves one byte though! – sweerpotato Nov 15 '15 at 12:12
• Yeah, you're right. – Kvam Nov 15 '15 at 12:13
• If you add using System; (13 bytes) you can do away with the System. (7 bytes) twice, saving 1 byte. – Kenney Nov 15 '15 at 18:46

# MarioLANG, 11 bytes

+<
:"
>!
=#


Inspired by Martin Büttner's answer in another question.

• Are you sure this works without problems to 2^128? – flawr Nov 14 '15 at 13:55
• – Martin Ender Nov 14 '15 at 14:00
• @flawr MarioLANG has a Ruby interpreter, and Ruby's integer type has arbitrary precision. – Martin Ender Nov 14 '15 at 14:01
• @flawr It depends on the interpreter. The interpreter I'm using is written in Ruby, and it supports arbitrary precision. – alephalpha Nov 14 '15 at 14:02

## 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, 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])));}

• In fact it should not terminate. That's the meaning of forever – edc65 Nov 14 '15 at 17:55

# Foo, 6 bytes

(+1$i)  ### Explanation ( ) Loop +1 Add one to current element$i     Output current element as a decimal integer


## 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.

## Perl, 3432302826 23 bytes

-Mbigint -E '{say$_+=1;redo}'  Test with perl -Mbigint -E '{say$_+=1;redo}'

• You can replace for(,,){...} with {...;redo} for two. – primo Nov 15 '15 at 0:14
• Yes I saw (perl 5.18+), but I thought it might be cheating; then the answers would be the same. I'm new here, so ;-) – Kenney Nov 15 '15 at 0:23
• Scalar references will be auto-vivified as SV UNDEF, which when incremented won't trigger the BigInt overload - because it's not a BigInt. Integer literals, however, are created as BigInts. Not so odd really ;) – primo Nov 16 '15 at 16:13
• Could you use $- to keep it as an integer and return to using ++$-? – Dom Hastings Nov 24 '15 at 7:39
• @DomHastings I tested with perl -Mbigint -E '{say++$-;$-+=\$-;redo}' | more and it wraps around to 1. It stays an int but bigint doesn't step in, unfortunately. – Kenney Nov 24 '15 at 11:17

## Marbelous, 358 bytes

..@F..@E..@D..@C..@B..@A..@9..@8..@7..@6..@5..@4..@3..@2..@1..@001@Z01
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

## 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)

• +1 ... sorry about all the extras. To get you a couple back you could try a=gmp::as.bigz(0);repeat{cat(paste(a<-a+1,''))}. You may want to make a note that gmp is an external library that may need downloading. – MickyT Nov 18 '15 at 22:10
• 44 bytes :) – Giuseppe Jan 18 '18 at 14:19