71
\$\begingroup\$

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.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

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

\$\endgroup\$
  • 29
    \$\begingroup\$ 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. \$\endgroup\$ – Dennis Nov 14 '15 at 14:25
  • 6
    \$\begingroup\$ For future challenges, may I recommend the sandbox such that all these details could be sorted out before people start posting answers? :) \$\endgroup\$ – Martin Ender Nov 14 '15 at 14:32
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ – Sparr Nov 15 '15 at 7:41
  • 5
    \$\begingroup\$ Can we have leading zeroes in the output? \$\endgroup\$ – Paŭlo Ebermann Nov 15 '15 at 11:43
  • 4
    \$\begingroup\$ 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+! \$\endgroup\$ – gregsdennis Nov 15 '15 at 20:45

186 Answers 186

63
\$\begingroup\$

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
\$\endgroup\$
  • 78
    \$\begingroup\$ The program is sad that its not stopping.. \$\endgroup\$ – Optimizer Nov 14 '15 at 17:10
  • 7
    \$\begingroup\$ @Optimizer def sad( indeed ): \$\endgroup\$ – YoYoYonnY Nov 16 '15 at 18:11
  • 1
    \$\begingroup\$ Why is this not 4 bytes? \$\endgroup\$ – Aurel Bílý Dec 30 '15 at 11:17
  • 2
    \$\begingroup\$ @Aurel300 The fifth byte is the newline between : and \ \$\endgroup\$ – Sp3000 Dec 30 '15 at 12:10
  • \$\begingroup\$ @Sp3000 Ah, yes. Silly me. :) \$\endgroup\$ – Aurel Bílý Dec 30 '15 at 15:04
46
\$\begingroup\$

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

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

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

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
\$\endgroup\$
21
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Would printing binary be any shorter? \$\endgroup\$ – SuperJedi224 Nov 14 '15 at 20:15
  • 3
    \$\begingroup\$ (or what about unary?) \$\endgroup\$ – Doorknob Nov 14 '15 at 21:58
  • \$\begingroup\$ @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 \$\endgroup\$ – TheDoctor Nov 14 '15 at 21:59
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – overactor Dec 30 '15 at 8:53
  • \$\begingroup\$ Eventually I'm going to push a commit to marbelous.py that includes all of include/ by default \$\endgroup\$ – Sparr Feb 6 at 2:55
18
\$\begingroup\$

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);}
\$\endgroup\$
  • 1
    \$\begingroup\$ So if those pointers are at each 64 bit, you could only count to 2^128-1, right? \$\endgroup\$ – flawr Nov 14 '15 at 14:15
  • 6
    \$\begingroup\$ Invalid as it can't count up to 2^128 \$\endgroup\$ – edc65 Nov 14 '15 at 14:52
  • 14
    \$\begingroup\$ 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. \$\endgroup\$ – flodel Nov 14 '15 at 17:44
  • 3
    \$\begingroup\$ I thought the words "at least as far as 2^128" were clear enough... \$\endgroup\$ – vrwim Nov 14 '15 at 18:00
  • 5
    \$\begingroup\$ @vrwim You didn't write that. You wrote "until 2^128". SuperJedi edited it a few minutes ago. \$\endgroup\$ – feersum Nov 14 '15 at 18:07
17
\$\begingroup\$

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.

\$\endgroup\$
13
\$\begingroup\$

Pyth, 4 bytes

.V1b

Explanation:

.V1    for b in range(1 to infinity):
   b      print b
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Sok Jul 12 at 14:03
  • \$\begingroup\$ @Sok Clever. However, I won't change the answer because I think that f was a feature oft Pyth 4 years ago. \$\endgroup\$ – Jakube Jul 12 at 15:23
  • \$\begingroup\$ 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 \$\endgroup\$ – Sok Jul 12 at 16:51
13
\$\begingroup\$

bc, 10

for(;;)++i

Unusual that bc is shorter than dc.

From man bc:

DESCRIPTION

bc is a language that supports arbitrary precision numbers

\$\endgroup\$
  • \$\begingroup\$ Where does this print it out? \$\endgroup\$ – Bálint Apr 24 '16 at 7:47
  • \$\begingroup\$ @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. \$\endgroup\$ – Digital Trauma Apr 24 '16 at 7:52
  • \$\begingroup\$ I don't have a single Linux terminal in my house. I was just curious. \$\endgroup\$ – Bálint Apr 24 '16 at 8:04
  • 7
    \$\begingroup\$ @Bálint Every house should have a Linux terminal. \$\endgroup\$ – Digital Trauma Apr 24 '16 at 8:09
  • 1
    \$\begingroup\$ @Bálint Running this program is your use ;) \$\endgroup\$ – Insane Apr 24 '16 at 18:32
12
\$\begingroup\$

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));}}
\$\endgroup\$
  • 2
    \$\begingroup\$ A smaller infinite loop in java is for(;;) for an easy 3 bytes. \$\endgroup\$ – ankh-morpork Nov 14 '15 at 17:29
  • \$\begingroup\$ 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. \$\endgroup\$ – TWiStErRob Nov 14 '15 at 19:46
  • \$\begingroup\$ And then another 9, because you can get rid of the import by referencing BigInteger by FQCN only once. \$\endgroup\$ – TWiStErRob Nov 14 '15 at 19:47
  • \$\begingroup\$ @TWiStErRob Somehow, I hadn't realized that would be shorter. \$\endgroup\$ – SuperJedi224 Nov 14 '15 at 20:05
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Luca H Nov 24 '17 at 6:55
10
\$\begingroup\$

Mathematica, 22 bytes

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

Echo is a new function in Mathematica 10.3.

\$\endgroup\$
  • \$\begingroup\$ 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]. \$\endgroup\$ – Roman Jul 14 at 18:08
7
\$\begingroup\$

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 :)
\$\endgroup\$
  • \$\begingroup\$ @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: \$\endgroup\$ – Addison Crump Nov 15 '15 at 20:26
7
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ 1 is a truthy value in Python (and most other languages). So while 1: is enough. \$\endgroup\$ – Jakube Nov 14 '15 at 12:49
  • \$\begingroup\$ Also, you can put the whole while on one line \$\endgroup\$ – Sp3000 Nov 14 '15 at 12:51
  • \$\begingroup\$ 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) \$\endgroup\$ – wnnmaw Nov 16 '15 at 21:00
  • 1
    \$\begingroup\$ You can not use repr instead of print. repr does not output anything. @wnnmaw \$\endgroup\$ – Zach Gates Nov 17 '15 at 19:47
  • \$\begingroup\$ What does repr do then? \$\endgroup\$ – flawr Nov 17 '15 at 19:52
6
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – SuperJedi224 Nov 14 '15 at 15:55
  • \$\begingroup\$ Yeah, just fixed that. \$\endgroup\$ – geokavel Nov 14 '15 at 15:56
  • \$\begingroup\$ Does Processing allow the BigInteger.ONE to be changed toi.ONE? \$\endgroup\$ – SuperJedi224 Nov 14 '15 at 16:05
  • \$\begingroup\$ @SuperJedi224 Yes, it does. Thanks! \$\endgroup\$ – geokavel Nov 14 '15 at 16:16
  • \$\begingroup\$ Alright, have an upvote. \$\endgroup\$ – SuperJedi224 Nov 14 '15 at 16:28
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – cat Dec 29 '15 at 15:58
  • 1
    \$\begingroup\$ @cat Samau is written in Haskell, and it's lazy. It won't generate the whole list before printing it. \$\endgroup\$ – alephalpha Dec 30 '15 at 2:48
  • \$\begingroup\$ Just a heads up. On the GitHub page for Samau, in the description of @, "push" is misspelt. \$\endgroup\$ – Carcigenicate Mar 31 '17 at 22:39
  • \$\begingroup\$ @Carcigenicate Thank you. \$\endgroup\$ – alephalpha Apr 1 '17 at 4:10
6
\$\begingroup\$

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.

\$\endgroup\$
  • 12
    \$\begingroup\$ This is why I have a pop-up blocker. \$\endgroup\$ – Comintern Nov 14 '15 at 16:47
  • 1
    \$\begingroup\$ just saying: for(i=0;;)alert(i++) I don't think you need all of those controls \$\endgroup\$ – towc Dec 30 '15 at 13:47
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ – user81655 Dec 30 '15 at 13:53
  • 1
    \$\begingroup\$ oh, fair point... \$\endgroup\$ – towc Dec 30 '15 at 14:00
5
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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, \$\endgroup\$ – Kenney Nov 15 '15 at 2:23
  • \$\begingroup\$ @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. \$\endgroup\$ – felixphew Nov 15 '15 at 3:50
  • \$\begingroup\$ 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 \$\endgroup\$ – Zereges Nov 22 '15 at 20:52
  • \$\begingroup\$ How about the deprecated #import? \$\endgroup\$ – connectyourcharger Jul 3 at 20:35
5
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ You can save 8 bytes with class C{static void Main(){var b=System.Numerics.BigInteger.One;for(;;)System.Console.WriteLine(b++);}} :~)! \$\endgroup\$ – sweerpotato Nov 15 '15 at 11:16
  • 1
    \$\begingroup\$ 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++));}} \$\endgroup\$ – Kvam Nov 15 '15 at 12:09
  • \$\begingroup\$ You still need System. That saves one byte though! \$\endgroup\$ – sweerpotato Nov 15 '15 at 12:12
  • \$\begingroup\$ Yeah, you're right. \$\endgroup\$ – Kvam Nov 15 '15 at 12:13
  • \$\begingroup\$ If you add using System; (13 bytes) you can do away with the System. (7 bytes) twice, saving 1 byte. \$\endgroup\$ – Kenney Nov 15 '15 at 18:46
5
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

MarioLANG, 11 bytes

+<
:"
>!
=#

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

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

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.

\$\endgroup\$
4
\$\begingroup\$

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])));}
\$\endgroup\$
  • 4
    \$\begingroup\$ In fact it should not terminate. That's the meaning of forever \$\endgroup\$ – edc65 Nov 14 '15 at 17:55
4
\$\begingroup\$

Foo, 6 bytes

(+1$i)

Explanation

(    )    Loop
 +1       Add one to current element
   $i     Output current element as a decimal integer
\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

Perl, 34 32 30 28 26 23 bytes

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

Test with

perl -Mbigint -E '{say$_+=1;redo}'
\$\endgroup\$
  • \$\begingroup\$ You can replace for(,,){...} with {...;redo} for two. \$\endgroup\$ – primo Nov 15 '15 at 0:14
  • \$\begingroup\$ 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 ;-) \$\endgroup\$ – Kenney Nov 15 '15 at 0:23
  • 1
    \$\begingroup\$ 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 ;) \$\endgroup\$ – primo Nov 16 '15 at 16:13
  • 1
    \$\begingroup\$ Could you use $- to keep it as an integer and return to using ++$-? \$\endgroup\$ – Dom Hastings Nov 24 '15 at 7:39
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Kenney Nov 24 '15 at 11:17
4
\$\begingroup\$

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

\$\endgroup\$
4
\$\begingroup\$

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)

\$\endgroup\$
  • 1
    \$\begingroup\$ +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. \$\endgroup\$ – MickyT Nov 18 '15 at 22:10
  • \$\begingroup\$ 44 bytes :) \$\endgroup\$ – Giuseppe Jan 18 '18 at 14:19
4
\$\begingroup\$

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.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.