88
\$\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\$
26
  • 35
    \$\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
    Commented Nov 14, 2015 at 14:25
  • 8
    \$\begingroup\$ For future challenges, may I recommend the sandbox such that all these details could be sorted out before people start posting answers? :) \$\endgroup\$ Commented Nov 14, 2015 at 14:32
  • 4
    \$\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
    Commented Nov 15, 2015 at 7:41
  • 5
    \$\begingroup\$ Can we have leading zeroes in the output? \$\endgroup\$ Commented Nov 15, 2015 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\$ Commented Nov 15, 2015 at 20:45

232 Answers 232

1
2 3 4 5
8
66
\$\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\$
5
  • 87
    \$\begingroup\$ The program is sad that its not stopping.. \$\endgroup\$
    – Optimizer
    Commented Nov 14, 2015 at 17:10
  • 8
    \$\begingroup\$ @Optimizer def sad( indeed ): \$\endgroup\$
    – yyny
    Commented Nov 16, 2015 at 18:11
  • 1
    \$\begingroup\$ Why is this not 4 bytes? \$\endgroup\$ Commented Dec 30, 2015 at 11:17
  • 2
    \$\begingroup\$ @Aurel300 The fifth byte is the newline between : and \ \$\endgroup\$
    – Sp3000
    Commented Dec 30, 2015 at 12:10
  • \$\begingroup\$ @Sp3000 Ah, yes. Silly me. :) \$\endgroup\$ Commented Dec 30, 2015 at 15:04
57
\$\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\$
1
  • 76
    \$\begingroup\$ +1 for the impatient upvote-demanding implicit in a line of code that basically reads “plus one, now!”. \$\endgroup\$ Commented Nov 14, 2015 at 14:39
33
\$\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\$
14
  • 6
    \$\begingroup\$ Invalid as it can't count up to 2^128 \$\endgroup\$
    – edc65
    Commented Nov 14, 2015 at 14:52
  • 2
    \$\begingroup\$ @edc65 The spec says until 2^128, which is not inclusive. \$\endgroup\$
    – feersum
    Commented Nov 14, 2015 at 15:05
  • 24
    \$\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
    Commented Nov 14, 2015 at 17:44
  • 3
    \$\begingroup\$ I thought the words "at least as far as 2^128" were clear enough... \$\endgroup\$
    – vrwim
    Commented Nov 14, 2015 at 18:00
  • 8
    \$\begingroup\$ @vrwim You didn't write that. You wrote "until 2^128". SuperJedi edited it a few minutes ago. \$\endgroup\$
    – feersum
    Commented Nov 14, 2015 at 18:07
27
\$\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\$
12
  • \$\begingroup\$ Isn't there a symbol that generalizes map/mapM etc? \$\endgroup\$
    – JDługosz
    Commented Nov 16, 2015 at 2:41
  • \$\begingroup\$ @JDługosz: not that I know \$\endgroup\$
    – Bergi
    Commented Nov 16, 2015 at 3:09
  • \$\begingroup\$ Ah, 'cause it would still have to sequence the result to get the output to really happen. \$\endgroup\$
    – JDługosz
    Commented Nov 16, 2015 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
    Commented Dec 30, 2015 at 11:06
  • 2
    \$\begingroup\$ With leading [ allowed you could say main=print[1..] \$\endgroup\$ Commented Jul 23, 2016 at 12:36
25
\$\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\$
24
\$\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\$
5
  • \$\begingroup\$ Would printing binary be any shorter? \$\endgroup\$ Commented Nov 14, 2015 at 20:15
  • 3
    \$\begingroup\$ (or what about unary?) \$\endgroup\$
    – Doorknob
    Commented Nov 14, 2015 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
    Commented Nov 14, 2015 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
    Commented Dec 30, 2015 at 8:53
  • \$\begingroup\$ Eventually I'm going to push a commit to marbelous.py that includes all of include/ by default \$\endgroup\$
    – Sparr
    Commented Feb 6, 2019 at 2:55
19
\$\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\$
0
17
\$\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\$
10
  • \$\begingroup\$ Where does this print it out? \$\endgroup\$
    – Bálint
    Commented Apr 24, 2016 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\$ Commented Apr 24, 2016 at 7:52
  • \$\begingroup\$ I don't have a single Linux terminal in my house. I was just curious. \$\endgroup\$
    – Bálint
    Commented Apr 24, 2016 at 8:04
  • 13
    \$\begingroup\$ @Bálint Every house should have a Linux terminal. \$\endgroup\$ Commented Apr 24, 2016 at 8:09
  • 3
    \$\begingroup\$ @Bálint Running this program is your use ;) \$\endgroup\$
    – Insane
    Commented Apr 24, 2016 at 18:32
14
\$\begingroup\$

Pyth, 4 bytes

.V1b

Explanation:

.V1    for b in range(1 to infinity):
   b      print b
\$\endgroup\$
3
  • \$\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
    Commented Jul 12, 2019 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
    Commented Jul 12, 2019 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
    Commented Jul 12, 2019 at 16:51
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\$
10
  • 2
    \$\begingroup\$ A smaller infinite loop in java is for(;;) for an easy 3 bytes. \$\endgroup\$ Commented Nov 14, 2015 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
    Commented Nov 14, 2015 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
    Commented Nov 14, 2015 at 19:47
  • \$\begingroup\$ @TWiStErRob Somehow, I hadn't realized that would be shorter. \$\endgroup\$ Commented Nov 14, 2015 at 20:05
  • 3
    \$\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
    Commented Nov 24, 2017 at 6:55
10
\$\begingroup\$

Mathematica, 22 bytes

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

Echo is a new function in Mathematica 10.3.

\$\endgroup\$
1
  • \$\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
    Commented Jul 14, 2019 at 18:08
9
\$\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\$
9
  • \$\begingroup\$ 1 is a truthy value in Python (and most other languages). So while 1: is enough. \$\endgroup\$
    – Jakube
    Commented Nov 14, 2015 at 12:49
  • \$\begingroup\$ Also, you can put the whole while on one line \$\endgroup\$
    – Sp3000
    Commented Nov 14, 2015 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
    Commented Nov 16, 2015 at 21:00
  • 2
    \$\begingroup\$ You can not use repr instead of print. repr does not output anything. @wnnmaw \$\endgroup\$
    – Zach Gates
    Commented Nov 17, 2015 at 19:47
  • 1
    \$\begingroup\$ you can reduce 1 more byte by making it Python 2 and making it print k \$\endgroup\$ Commented Jul 19, 2017 at 20:07
8
\$\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\$
1
  • \$\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\$ Commented Nov 15, 2015 at 20:26
8
\$\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\$
5
  • \$\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
    Commented Dec 29, 2015 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
    Commented Dec 30, 2015 at 2:48
  • \$\begingroup\$ Just a heads up. On the GitHub page for Samau, in the description of @, "push" is misspelt. \$\endgroup\$ Commented Mar 31, 2017 at 22:39
  • \$\begingroup\$ @Carcigenicate Thank you. \$\endgroup\$
    – alephalpha
    Commented Apr 1, 2017 at 4:10
  • 1
    \$\begingroup\$ Just a heads up. On the GitHub page for Samau, in the description of _, "opposite" is misspelt. \$\endgroup\$ Commented Jan 25, 2022 at 6:58
8
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jan 15, 2020 at 3:05
7
\$\begingroup\$

makina, 22 bytes

v
>Pv
^>OC
^Uu>n0;
^O<

I AM REAL HUMAN YOU SHOULD TRUST ME AND DO WHAT I SAY

\$\endgroup\$
1
  • \$\begingroup\$ (I posted this challenge to get this account enough rep to use chat) \$\endgroup\$
    – Ginger
    Commented Oct 5, 2022 at 15:17
6
\$\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\$
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\$
10
  • \$\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\$ Commented Nov 14, 2015 at 15:55
  • \$\begingroup\$ Yeah, just fixed that. \$\endgroup\$
    – geokavel
    Commented Nov 14, 2015 at 15:56
  • \$\begingroup\$ Does Processing allow the BigInteger.ONE to be changed toi.ONE? \$\endgroup\$ Commented Nov 14, 2015 at 16:05
  • \$\begingroup\$ @SuperJedi224 Yes, it does. Thanks! \$\endgroup\$
    – geokavel
    Commented Nov 14, 2015 at 16:16
  • \$\begingroup\$ Alright, have an upvote. \$\endgroup\$ Commented Nov 14, 2015 at 16:28
6
\$\begingroup\$

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.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ I was able to get it down to 68 bytes by merging the last 3 substitutions. Try it online! \$\endgroup\$
    – Jiří
    Commented Jan 14, 2023 at 18:33
  • 2
    \$\begingroup\$ @Jiří Fine, but why not golf it further down by also replacing /^9*$/s/^/0/ by s/^9*$/0&/ reducing to 66 bytes \$\endgroup\$
    – Philippos
    Commented Sep 19, 2023 at 10:49
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\$
7
  • 14
    \$\begingroup\$ This is why I have a pop-up blocker. \$\endgroup\$
    – Comintern
    Commented Nov 14, 2015 at 16:47
  • 1
    \$\begingroup\$ just saying: for(i=0;;)alert(i++) I don't think you need all of those controls \$\endgroup\$
    – towc
    Commented Dec 30, 2015 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
    Commented Dec 30, 2015 at 13:53
  • 1
    \$\begingroup\$ oh, fair point... \$\endgroup\$
    – towc
    Commented Dec 30, 2015 at 14:00
  • \$\begingroup\$ this is simpler: (function x(e){alert(e);x(++i)}(i=0)) (37 bytes) \$\endgroup\$
    – derder56
    Commented Aug 18, 2020 at 0:09
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\$
5
  • \$\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
    Commented Nov 15, 2015 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
    Commented Nov 15, 2015 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
    Commented Nov 22, 2015 at 20:52
  • \$\begingroup\$ How about the deprecated #import? \$\endgroup\$
    – moltarze
    Commented Jul 3, 2019 at 20:35
  • \$\begingroup\$ using printf(3) won't work here as the %u conversion specifier casts the argument to unsigned int so it will loop after 2^32 (for 32-bit int). You should instead use std::cout as boost overloads operator<< for uint512_t. Suggest using int512_t since it's one byte shorter and can also get to 2^128, also you can use space or comma as separator to save another byte \$\endgroup\$
    – c--
    Commented May 31, 2023 at 17:28
5
\$\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\$
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\$
2
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – Kirill L.
    Commented Feb 26, 2021 at 15:19
  • \$\begingroup\$ Yup that's true :) \$\endgroup\$
    – dmh
    Commented Feb 26, 2021 at 15:21
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 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

\$\endgroup\$
12
  • \$\begingroup\$ You can save 8 bytes with class C{static void Main(){var b=System.Numerics.BigInteger.One;for(;;)System.Console.WriteLine(b++);}} :~)! \$\endgroup\$ Commented Nov 15, 2015 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
    Commented Nov 15, 2015 at 12:09
  • \$\begingroup\$ You still need System. That saves one byte though! \$\endgroup\$ Commented Nov 15, 2015 at 12:12
  • \$\begingroup\$ Yeah, you're right. \$\endgroup\$
    – Kvam
    Commented Nov 15, 2015 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
    Commented Nov 15, 2015 at 18:46
4
\$\begingroup\$

MarioLANG, 11 bytes

+<
:"
>!
=#

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

\$\endgroup\$
4
  • \$\begingroup\$ Are you sure this works without problems to 2^128? \$\endgroup\$
    – flawr
    Commented Nov 14, 2015 at 13:55
  • 1
    \$\begingroup\$ This looks familiar. :) \$\endgroup\$ Commented Nov 14, 2015 at 14:00
  • \$\begingroup\$ @flawr MarioLANG has a Ruby interpreter, and Ruby's integer type has arbitrary precision. \$\endgroup\$ Commented Nov 14, 2015 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
    Commented Nov 14, 2015 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\$
0
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\$
1
  • 4
    \$\begingroup\$ In fact it should not terminate. That's the meaning of forever \$\endgroup\$
    – edc65
    Commented Nov 14, 2015 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\$

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.

\$\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\$
1
2 3 4 5
8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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