87
\$\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

226 Answers 226

1
2
3 4 5
8
4
\$\begingroup\$

Perl, 34 32 30 28 26 23 bytes

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

Test with

perl -Mbigint -E '{say$_+=1;redo}'
\$\endgroup\$
13
  • \$\begingroup\$ You can replace for(,,){...} with {...;redo} for two. \$\endgroup\$
    – primo
    Commented Nov 15, 2015 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
    Commented Nov 15, 2015 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
    Commented Nov 16, 2015 at 16:13
  • 1
    \$\begingroup\$ Could you use $- to keep it as an integer and return to using ++$-? \$\endgroup\$ Commented Nov 24, 2015 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
    Commented Nov 24, 2015 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\$
2
  • 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
    Commented Nov 18, 2015 at 22:10
  • \$\begingroup\$ 44 bytes :) \$\endgroup\$
    – Giuseppe
    Commented Jan 18, 2018 at 14:19
4
\$\begingroup\$

Turing Machine Simulator, 536 bytes

a * * r a
a , * r A
A * * r A
A , * l b
b * * l b
b , * l c
b s 0 l 0
b p 1 l 1
b d 2 l 2
b f 3 l 3
b g 4 l 4
b h 5 l 5
b i 6 l 6
b j 7 l 7
b k 8 l 8
b l 9 l 9
0 * * l 0
0 _ s r a
1 * * l 1
1 _ p r a
2 * * l 2
2 _ d r a
3 * * l 3
3 _ f r a
4 * * l 4
4 _ g r a
5 * * l 5
5 _ h r a
6 * * l 6
6 _ i r a
7 * * l 7
7 _ j r a
8 * * l 8
8 _ k r a
9 * * l 9
9 _ l r a
c _ p l d
c s p l d
c p d l d
c d f l d
c f g l d
c g h l d
c h i l d
c i j l d
c j k l d
c k l l d
c l s l c
d * * l d
d _ , r A

Test it out here -> link
initial input: ,*p,
initial state: b

Explanation:
state a: move right until a comma is found then move to state A
state A: move right until a comma is found then move to state b
state b: move left until a letter or a comma is found. If a letter is found, change the letter to its corresponding digit and move to the corresponding state. If a comma is found, move to state c.
states 0-9: move left until an empty space is found then write the digit
state c: increment the number and end up on the left then move to state d
state d: place a comma then move to state A

Basically, it finds the previous number, copies it over while converting it to digits, increments it, then starts all over.

On a real turing machine this would go way over 2^128

\$\endgroup\$
4
  • \$\begingroup\$ You could save some bytes by converting this to use binary, I'm not sure whether or not that would improve speed any though \$\endgroup\$ Commented Feb 2, 2016 at 15:49
  • \$\begingroup\$ Not sure if binary is allowed in the rules, but unary would definitely be shorter \$\endgroup\$ Commented Feb 2, 2016 at 15:51
  • \$\begingroup\$ My BotEngine answer uses binary, at least. \$\endgroup\$ Commented Feb 2, 2016 at 16:00
  • \$\begingroup\$ The initial input can just be ,p, . Don't need the asterisk. \$\endgroup\$
    – ouflak
    Commented Dec 4, 2020 at 20:59
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\$
4
\$\begingroup\$

05AB1E, 4 bytes

[¼¾,

Explained

[           # start infinite loop
 ¼          # increase counter
  ¾         # push counter
   ,        # print with a newline
\$\endgroup\$
2
  • 1
    \$\begingroup\$ ASCII-only version: [N>, \$\endgroup\$ Commented Aug 22, 2017 at 15:12
  • \$\begingroup\$ Another 4-bytes alternative: 0[>= \$\endgroup\$ Commented Mar 5, 2019 at 14:21
4
\$\begingroup\$

Alice, 6 bytes

h .\
O

Try it online!

Alice is a 2D language with two modes - Cardinal (up/down/left/right) for integers and Ordinal (diagonal) for strings. For this challenge we need Cardinal to count and Ordinal to print as an integer (as opposed to a byte).

We start off from the top left in Cardinal mode, with h incrementing the top of stack — for the first iteration, this is an implicit 0. The space that follows is a no-op, and the . after duplicates the top of stack.

Next we pass through the mirror \, reflecting us NE and switching us to Alice's Ordinal mode. In Ordinal mode the IP reflects off the code boundary rather than wrapping around, so we rebound and start moving SW.

From here we bounce twice, hit the O to print as integer, and bounce back to the \. This switches us back to Cardinal mode moving rightward, wrapping around and continuing the infinite loop.

TL;DR:

0123  ->  h5.3  ->  h7 9  ->  01.9  ->  ...
O         6 4       6 8       O
\$\endgroup\$
4
\$\begingroup\$

Rust, 41 bytes

fn main(){for i in 1..{println!("{}",i)}}

Try it online!

\$\endgroup\$
0
3
\$\begingroup\$

C, 93

Count up to 10^97. Add 3 bytes to count up to 10^997 (and so on).

char*p,d[99],*q=d+97;main(){while(p-d)*q>56?(*q--=48):(*q||(*(p=q)=48),++*q,puts(p),q=d+97);}

Less golfed

char*p,d[99],*q=d+97;

main()
{
  while(p!=d)
  {
    if(*q > '8') {
      *q = '0';
      --q;
    }
    else {
      if (!*q) {
        *q = '0';
        p = q; 
      }
      ++*q;
      puts(p);
      q = d + 97;
    }
  }
}
\$\endgroup\$
3
\$\begingroup\$

Racket, 40 bytes

(sequence-for-each println(in-naturals))

Racket has arbitrary-precision numbers, so this will continue to count up forever.

\$\endgroup\$
3
\$\begingroup\$

Scala, 41 39 35 bytes

Stream.iterate(BigInt(0)){_+1}print

Other versions (I left all solutions there because they're significantly different):

def r(n:BigInt){println(n);r(n+1)};r(0)   // 39
var i=BigInt(0);while(1>0)println{i+=1;i} // 41

This is my first time writing Scala code.

Original idea based on SuperJedi224's Java answer.

{i=>i+1} can be shortened to {_+1}.
foreach println was replaced with print because the problem description allows any separator.
Iterator.iterate and Stream.iterate, though completely different, do the same thing.

Other tries

Stream.from(0).print() // overflows at Integer.MAX_VALUE
BigInt(0).to(10)foreach println // 10 should be BigInt.MAX_VALUE (=Infinity), which doesn't exist
def from(start:BigInt):Stream[BigInt]=Stream.cons(start,from(start+1));from(0).print // too long
\$\endgroup\$
4
  • \$\begingroup\$ Shouldn't println(i+=1) work just as well? \$\endgroup\$
    – Bergi
    Commented Nov 14, 2015 at 22:26
  • 1
    \$\begingroup\$ @Bergi no, assignments are not expressions in Scala: their type is Unit (void). I learned that the hard way by trying what you suggest, but REPL outputted (). See for example this on SO. This is the shortest version I could come up with based on this answer. Notice that also there's no increment (++i) operator for BigInts. \$\endgroup\$
    – TWiStErRob
    Commented Nov 14, 2015 at 22:37
  • \$\begingroup\$ Oh right. Sure, assignment is evil in Scala. More functional would be something like Stream.from(1).forEach(printLn _) I guess, but Stream.from seems to leak memory and not work with BigInts. \$\endgroup\$
    – Bergi
    Commented Nov 14, 2015 at 22:59
  • \$\begingroup\$ @Bergi added all my other tries to the answer. \$\endgroup\$
    – TWiStErRob
    Commented Nov 14, 2015 at 23:06
3
\$\begingroup\$

C, 95 bytes

int a,c[50]={-38};main(){for(a=49;++c[a]>9;c[a--]=0);for(a=0;a<50;++a)putchar(c[a]+48);main();}

Prints:

00000000000000000000000000000000000000000000000001
00000000000000000000000000000000000000000000000002
...
\$\endgroup\$
2
  • \$\begingroup\$ This recurses, not sure if the stack will hold 2^128 call frames.. \$\endgroup\$
    – Kenney
    Commented Nov 15, 2015 at 18:30
  • 3
    \$\begingroup\$ Tail-call optimization will take care of it, so it's no problem. Moreover, the C standard doesn't limit the stack size. \$\endgroup\$
    – lynn
    Commented Nov 15, 2015 at 19:36
3
\$\begingroup\$

Perl 6, 13 bytes

.say for 1..*
\$\endgroup\$
3
\$\begingroup\$

8086 machine code + DOS, 34 bytes

Hexdump:

30 0D 0A 24 FE C6 BB 00 01 B4 09 CD 21 FE 07 80
3F 3A 75 F2 C6 07 30 4B 3B DA 73 F1 C6 07 30 4A
EB EB

In assembly language:

    .MODEL TINY

    .CODE
    org 100h

MAIN PROC

    db '0',13,10,'$' ; output buffer
    inc dh ; assign dx=0x100 - address of the output buffer

increase_num:
    mov bx, 100h
    mov ah, 9
    int 21h ; print the number

increase_digit:
    inc byte ptr [bx]
    cmp byte ptr [bx], '0'+10
    jne increase_num
    mov byte ptr [bx], '0'
    dec bx
    cmp bx, dx
    jae increase_digit
    mov byte ptr [bx], '0'
    dec dx
    jmp increase_digit

MAIN ENDP
END MAIN

Some explanations:

Output buffer is at offset 0x100; it contains 4 bytes at first: '0', a newline sequence 0d 0a, and '$', which is an end-of-output-buffer byte that DOS uses. These 4 bytes are executed as nonsensical code:

xor [di],cl
or ah,[si]

This destroys the program exit instruction at offset 0, but this is OK because the program will not exit!

The instruction inc dh generates the value 0x100 in dx, which is the address of the output buffer. The output buffer grows down, decreasing the value of dx with each power of 10.

The number is stored as an ASCII string. The increment code starts from the last digit, increases it and checks whether it went out of range 0...9. If yes, it sets the digit to 0 and goes to the next digit (dec bx). If all digits are set to 0, it adds (dec dx) another 0 digit, and immediately increases it to 1.

\$\endgroup\$
1
  • \$\begingroup\$ I realize this is an old answer but I'm curious: How can you assume dx and di are zero-initialized? As far as I know their values are undefined on entry. \$\endgroup\$ Commented Apr 24, 2017 at 6:17
3
\$\begingroup\$

O, 7 bytes

1{.o)}w

Explanation:

1       Pushes 1 to the stack
 {   }w While the top of the stack is not 0
  .o)   Output the top of the stack and increment it

Does not work on online IDE, but does in REPL and file.

\$\endgroup\$
3
\$\begingroup\$

Burlesque, 9 bytes

1R@2SH[-Q

If you don't care what the first character is go with 1R@.

Explanation:

R@ is the RangeInf built-in and creates a Block with numbers [N..Infinity] so 1R@ generates a Block {1 2 3 4 5....}. However, if we display this we'll have a { at the start of our output which we don't want. SH converts a value to a display value (called Pretty) and then back to a String using the display format. 2 is the Format With Spaces so 2SH produces [1 2 3 4 5...]. Now we use [- which is the Tail built-in which removes the first character in that string. Q converts our string to a display value. Burlesque generally prints things as you input them, so when it prints a String there it will be surrounded by quotes. If one doesn't want that we have to convert it to a display value (called Pretty).

blsq ) "hi"
"hi"
blsq ) "hi"Q
hi
blsq ) 5ro
{1 2 3 4 5}
blsq ) 5ro2SH
"[1 2 3 4 5]"
blsq ) 5ro2SH[-
"1 2 3 4 5]"
blsq ) 5ro2SH[-Q
1 2 3 4 5]
\$\endgroup\$
3
  • \$\begingroup\$ BTW: Technically this displays a list as string with the first character removed. So it displays '1 2 3 4 5 ......]' but since it's infinite in size ']' will never be printed. \$\endgroup\$
    – mroman
    Commented Nov 14, 2015 at 13:29
  • \$\begingroup\$ Could you explain this code char by char? I tried the doc, but there's no easy way of searching. \$\endgroup\$
    – vrwim
    Commented Nov 14, 2015 at 23:35
  • 1
    \$\begingroup\$ I've added an explanation. \$\endgroup\$
    – mroman
    Commented Nov 16, 2015 at 10:26
3
\$\begingroup\$

Powershell, 43 29 bytes

[Numerics.BigInteger]$i=1;for(){$i;$i=$i+1}

Relies on .Net 4.0 and up for System.Numerics.BigInteger

V2

[BigInt]$i=0;for(){($i=$i+1)}

Thanks to TimmyD for the additional tips for use of parens to a automatically produce output and [bigint] for type assignment.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to PPCG! If you use PowerShell v4+, you can use the [bigint] alias instead of [Numerics.BigInteger]. Additionally, enclosing the variable in parens will automatically produce output, and using the inline ++ instead of assignment shortens as well. Results in [bigint]$i;for(){($i++)} for 24 Bytes. \$\endgroup\$ Commented Nov 16, 2015 at 14:06
  • \$\begingroup\$ @TimmyD Thanks for the tips! I'm using PowerShell 5.0, but couldn't use just [bigint]$i without getting an error. Ran into a few other gotchas with going with just ($i++). I can list them if it would be appropriate. \$\endgroup\$
    – Booga Roo
    Commented Nov 16, 2015 at 21:04
  • \$\begingroup\$ Interesting. v5 (or the behind-the-scenes .NET) must have updated/changed default initializations and/or the ++ operator overload. \$\endgroup\$ Commented Nov 16, 2015 at 21:21
  • 1
    \$\begingroup\$ For v5, you can still do for([BigInt]$i=0){($i+=1)} for 25 bytes \$\endgroup\$
    – Veskah
    Commented Jul 12, 2019 at 13:08
3
\$\begingroup\$

PARI/GP, 23 bytes

i=0;until(print(i+=1),)

Sample Usage

$ gp -qf < countup.gp
\$\endgroup\$
3
\$\begingroup\$

Brainfuck, 44 bytes

->-<[>>[->>]<[+>>-<<]>+>+[->>+]-<+[-.<<+]-.]

I'm surprised there are no brainfuck submissions, so here's my attempt (and my first brainfuck program). I interpreted the constraint on number formatting as 'whatever is convenient for your language', so the output here is as a binary string of 00 and 01, with FF as separators. The beginning of the output:

0000000: 01 ff 01 00 ff 01 01 ff 01 00 00 ff 01 00 01 ff  ................
0000010: 01 01 00 ff 01 01 01 ff 01 00 00 00 ff 01 00 00  ................

The standard 30000 byte BF implementation can go as high as 2^15000 before reaching undefined behavior. Here is another version which produces a more readable output consisting of "0" and "1" with newlines as separators (currently 105 chars, although this can probably be golfed more):

++++++++++>>->-<[>>[->>]<[+>>-<<]>+>+[->>+]-<+[-[-<+<<+>>>]++++++[-<++++++++>]<.[-]<<[->>>+<<<]>+]-<<.>>]

Output:

1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
\$\endgroup\$
3
\$\begingroup\$

Mathematica, 22 bytes

For[i=1,1>0,Print@i++]
\$\endgroup\$
3
\$\begingroup\$

Seriously, 4 bytes

1W■u

Explanation:

1    puts 1 on the stack
W    begins a while loop that executes while the (peeked) value on top of the stack is truthy
  ■    output entire stack without popping
  u    increment value on top of stack
<EOF> implicit end of while loop block

No online interpreter link because it doesn't do so well with infinite loops.

\$\endgroup\$
3
\$\begingroup\$

Pyth, 4 bytes

.V1b

.V begins an infinite loop which defines incremented b, starting with 1. The body of the loop implicitly prints b on the next line.

\$\endgroup\$
3
\$\begingroup\$

dc, 12 bytes

Uses an "anonymous" recursive macro, should be able to run for ever:

z[r1+prdx]dx
\$\endgroup\$
2
  • 1
    \$\begingroup\$ For once, bc is shorter \$\endgroup\$ Commented Nov 14, 2015 at 21:17
  • \$\begingroup\$ The 11-byte solution is invalid: you cannot store a unary representation of the current number in memory. And besides it starts from 0 rather than from 1. \$\endgroup\$
    – user46915
    Commented Nov 16, 2015 at 11:57
3
\$\begingroup\$

WhoScript, 28 27 bytes

1#1;v;e;pw #;#a;pw;#1;+;i;d

Ungolfed/Explanation:

# 1                        @ push 1 to the stack
time_vortex                @ begin an infinite loop
  duplicate                @ duplicates the top of the stack
  psychic_paper write #    @ prints the top of the stack as a number
  # a                      @ pushes 10 (0xA) to the stack
  psychic_paper write      @ prints the character whose ASCII code matches the top of the stack
  # 1                      @ pushes another 1 to the stack
  +                        @ adds the top two stack values (as a floating point number)
  integer                  @ converts the top number of the stack to an integer
paradox                    @ go back to the 'time_vortex' line

Shaved off a byte by using 0xA instead of 0x20

\$\endgroup\$
3
\$\begingroup\$

Fuzzy Octo Guacamole, 4 bytes

(+X)

Explanation:

(+X)
(  )    # Infinite loop.
 +      # Increment ToS, which is 0 by default.
  X     # Print ToS.
        # Implicit output applies to the end of a loop.
\$\endgroup\$
1
  • \$\begingroup\$ This is a catalogue, not a challenge, so no problem submitting when the language is newer than the question \$\endgroup\$
    – vrwim
    Commented Apr 25, 2016 at 14:19
3
\$\begingroup\$

Sesos, 2 bytes

Hexdump:

0000000: 0c3a                                              .:

Try it online!

Assembly:

set numout ;output one number per line instead of character
nop        ;set entry marker (start of loop)
add 1
put
           ;(implicit jnz) set exit marker (end of loop, jump if not zero)
\$\endgroup\$
3
\$\begingroup\$

Brachylog, 6 bytes

#>=@w\

Try it online!

Explanation

#>         Constrain a number in [1,∞)
  =        Assign a value to the number in that interval
   @w      Write the number followed by a linebreak
     \     False ; try another value assignement in the interval
\$\endgroup\$
3
\$\begingroup\$

ArnoldC, 157 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP 0
STICK AROUND 1
GET TO THE CHOPPER n
GET UP 1
ENOUGH TALK
TALK TO THE HAND n
CHILL
YOU HAVE BEEN TERMINATED

First time trying to use ArnoldC so any improvements are welcome. I ran it here and it seemed to work even though the output stops around 1700. I believe this is a limitation of that test though, not the code.

\$\endgroup\$
3
\$\begingroup\$

cQuents, 1 byte

$

Try it online!

Explanation

:    Implicit mode : (infinitely print the sequence if given no input)
 $   Each item in the sequence equals the current (1-based) index
\$\endgroup\$
3
\$\begingroup\$

Brainfuck, 1055 bytes

+>+<[>[>[-]+<-]>[<+>>>>>>>>>[-]>[-]<[>+<-]<<<<<<<<-]>>>>>>>>>>>[<<<<<<<<<<<<+>>>>>>>>>>>>-]<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>+>[-]<[>+<-][-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[-]<<[<<<<<<+>>>>>>-]->>[<<<<<<<<-<+>>>>>>>>>-]<<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]>[>>>>>>+<<<<<<[-]]<->>>>>>>[<<<<<<<->>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[>>>>+<<<<<<<<<<<<<->>>>>>>>>[-]]<<<<<<<<-]<[>[-]+<-]>[<+>>>>>>>>>>>>>>+<<<<<<<<<<<<<<->-]>>>>>>>>>>>>[<<<<<<<<<<<<<+>>>>>>>>>>>>>-]<<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>[-]>[-]>[-]>[-]>>>[<<<<+[>+<<<<+>>>-]<<<[>>>+<<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>>+>[-]<<<-]>>[>>+<<<<+>>-]<<[>>+<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>+>[-]<<-]>>>>>>>-]<<<<<<[<++++++++[>++++++>++++++<<-]>.>.[-]<[-]]>[<<++++++++[>>++++++<<-]>>.[-]]<<++++++++[>>>++++++<<<-]>>>.[-]<<<++++[>++++++++<-]>.[-]<>>>>>>>>>>+<<<<<<<<<<<<->-]>>>>>>>>>>>>>[<<<<<<<<<<<<<<+>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>[-]+<-]>[<+<->>-]<<]

Too bad that Brainfuck has limited memory cell size. Actually, printing decimals and conditional statements are pain in this language. Ungolfed (or called so):

+>+<[

COUNTER=0

>[>[-]+<-]>[<+

>>>>>>>>>>[-]

LOOP START
    INCREMENTING <<<<<<<<<-]>>>>>>>>>>>[<<<<<<<<<<<<+>>>>>>>>>>>>-]<<<<<<<<<<<<[>[-]+<-]>[<+>>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>+>[-]<[>+<-]
    CHECKING CELL [-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[-]<<[<<<<<<+>>>>>>-]->>[<<<<<<<<-<+>>>>>>>>>-]<<<<<<<<<[>>>>>>>>>+<<<<<<<<<-]>[>>>>>>+<<<<<<[-]]<->>>>>>>[<<<<<<<->>>>>>>-]<<<<<<<[>>>>>>>+<<<<<<<-]>>>>>>>[>>>>+<<<<<<<<<<<<<->>>>>>>>>[-]]<<<<<<<<-]<[>[-]+<-]>[<+>>>>>>>>>>>>>>+<<<<<<<<<<<<<<->-]>>>>>>>>>>>>  [<<<<<<<<<<<<<+>>>>>>>>>>>>>-]


    PRINTING
                <<<<<<<<<<<<<[>[-]+<-]>[<+

                PRINT INTEGER

                >>>>>>>>>[-]>[<+<<<<<<<+>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]>[-]>[-]>[-]>[-]>>>[<<<<+[>+<<<<+>>>-]<<<[>>>+<<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>>+>[-]<<<-]>>[>>+<<<<+>>-]<<[>>+<<-]+>>>>----------[<<<<->>>>[-]]<<<<[>+>[-]<<-]>>>>>>>-]<<<<<<[<++++++++[>++++++>++++++<<-]>.>.[-]<[-]]>[<<++++++++[>>++++++<<-]>>.[-]]<<++++++++[>>>++++++<<<-]>>>.[-]

                PRINT SPACE

                <<<++++[>++++++++<-]>.[-]<


LOOP END

CODE THAT GETS EXECUTED AT THE END (LEAVING LOOP):

>>>>>>>>>>+<<<<<<<<<<<<->-]>>>>>>>>>>>>>[<<<<<<<<<<<<<<+>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<[>[-]+<-]>[<+<->>-]<<]

If we would remove last piece of code it would stick two '1' at the end.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Welcome to PPCG! There is already a brainfuck answer here, but multiple answers in the same language are perfectly fine here. Nice answer! \$\endgroup\$ Commented Oct 24, 2017 at 15:54
  • \$\begingroup\$ "Printing decimals and conditional statements are a pain in this language." Everything is a pain in brainfuck. That's sort of the point. \$\endgroup\$
    – KSmarts
    Commented Nov 17, 2017 at 15:15
  • \$\begingroup\$ @KSmarts Not really, some things are ridicously easy \$\endgroup\$ Commented Nov 17, 2017 at 19:17
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.