# Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.
This is not the same thing. That one is about counting up indefinitely.

# Challenge

Write a program or function that prints every integer from 1 to n inclusive.

# Rules

• You can get n any way.
• You can assume that n will always be a positive integer.
• You can get n in any base, but you should always output in decimal.
• Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).
• Standard loopholes are denied.
• We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.
• You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).
• You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

# Bonuses

## 20%

• Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

• Related. Apr 25, 2016 at 12:20
• "You can get n any way." Does that mean we can assume n to be saved in a variable? May 21, 2016 at 20:50
• @flawr You can get n any way. You can save it in a variable, but it must not be hardcoded. May 22, 2016 at 10:26
• It might be useful to link to the accepted I/O methods Jun 2, 2017 at 12:26
• @Ephphatha Yes it probably is, this challenge is from the old times where I was an utter newb. Jun 2, 2017 at 12:29

## Perl 5, 15 bytes + 8

Works with the -l and -Mbigint switch, and should work up to 2^64 with BigInt. Thanks to @andlrc for the 7 bytes shaved off.

print for 1..<>

• You should use BigInt then. Apr 25, 2016 at 13:45
• But you can do arbitary precision, thus you can count to pretty much infinite (2^65536 at least) Apr 25, 2016 at 14:52
• You can use print for 1..<> Apr 25, 2016 at 15:33
• @ΈρικΚωνσταντόπουλος Edited to match this.
– Sake
Apr 26, 2016 at 6:49
• @Bálint How so? I'm not aware of this in Perl... Did a bit of research on the Perl documentation, but I haven't found anything I guess... :(
– Sake
Apr 26, 2016 at 6:51

# AutoHotKey

I wasn't the first to post an answer in AHK, but mine are shorter for now. AutoHotKey doesn't like golf so the golfed versions are the same as the ungolfed versions. As for AutoHotKey's integer support:

For integers, 64-bit signed values are supported, which range from -9223372036854775808 (-0x8000000000000000) to 9223372036854775807 (0x7FFFFFFFFFFFFFFF). Any integer constants outside this range are not supported and might yield inconsistent results. By contrast, arithmetic operations on integers wrap around upon overflow (e.g. 0x7FFFFFFFFFFFFFFF + 1 = -0x8000000000000000).

# Really Annoying Version - 25 bytes

Prints each number in a message box (super annoying) and takes input as the first argument on the command line.

i=1
Loop %1%
MsgBox % i++


i=1 - Loop counter set at 1
Loop %1% - Loop as many times as specified on the CLI
MsgBox % i++ = Display a message box with the digit in it, then increment

# Alternate, Less Annoying Version - 43 bytes

This version displays only one message box but is much longer.

i=1
j=
Loop %1%
j:=j . i++ . " "
MsgBox %j%


i=1 - Loop counter set at 1
j= - Variable j set to an empty string
Loop %1% - Loop as many times as specified on the CLI
j:=j . i++ . " " - concatenate i and a space to j, then increment i
MsgBox %j% = Display a message box with j in it

• I hope there's a way to escape the loop! Counting just to 30 would be incredibly annoying. Apr 26, 2016 at 6:14
• @StewieGriffin I mean, you can kill the process... But otherwise, no. Apr 26, 2016 at 11:46
• I think in the maximum signed int64 value you have 2 extra Fs. May 2, 2016 at 12:45
• Here's a 26 byte less annoying version using Send as the output method (using \n to indicate a new line in the program because I need to use the accent/backtick in the program that messes with SE): Loop,%1%{ \n i++ \n Send, %i% \n } Mar 28, 2017 at 12:45

# Jolf, 29 + 1 = 30 bytes

This in fact is valid! It uses the same technique as the JavaScript answer, keeping an array of digits. It should thus theoretically work, but may not work due to time limitations (browser crashing, etc.) Make sure to have "Pretty Output" enabled if it isn't already. (Apparently, making sure is an extra byte, like a flag, so there's that.) Try it here!

Ζ²1W<ni)aRζEΖZWζγwlζh.ζγonhn}


Ungolfed:

Z ~: 1
W < n i )
a R ζ E
Ζ ZW
ζ
w lζ
h .ζ w lζ
on h n
}


That's real clean-looking for a golfing language! :D

• What encoding is this? Apr 26, 2016 at 18:16
• You should add 1 byte because I must choose pretty output on. Apr 26, 2016 at 18:17
• @ΈρικΚωνσταντόπουλος You are right on the latter. Also, it's encoded in ISO-8859-7. You can upload a file on the website. (It's the encoding that bears your name in 1-byte characters ;)) Apr 26, 2016 at 18:22
• That's right. 2 more to go... Apr 26, 2016 at 18:41
• I don't think the encoding has to do something with here, as my name uses Unicode I think. Apr 29, 2016 at 17:40

# C, 61 bytes

long i,n;main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}


Essentially the same as my C++ answer, but C (or gcc) is more lenient of missing #includes, a missing return-type for main, and missing return-statements.

• I disagree. Not all compilers support missing #includes. So you should add 18 bytes. Apr 27, 2016 at 12:35
• gcc is considered sort of a golden standard as far as C compilers are concerned. Since default gcc has always supported missing #include <stdio.h>, and corner-cutting is in general encouraged in code-golf, I still think this is legit. @Dennis seems to agree in a comment to this question. Apr 27, 2016 at 13:07
• You mean this comment? Apr 27, 2016 at 13:18
• Yes - and thanks to you, I now know how to link comments :-) Apr 27, 2016 at 16:17
• Remember, you always learn, no matter your age. The date of the comment is it's link (click on it to be linked to that particular comment). Apr 27, 2016 at 17:29

# Oracle SQL 11.2, 44 bytes

SELECT LEVEL FROM DUAL CONNECT BY LEVEL<=:1;

• Nice to see an answer in SQL derivatives! Apr 27, 2016 at 15:01

# C++, 92 81 bytes

#include<cstdio>
long i,n;int main(){for(scanf("%ld",&n);i++<n;printf("%ld ",i));}


And another version, using iostream, with the same byte count

#include<iostream>
long i,n;int main(){for(std::cin>>n;i++<n;std::cout<<i<<' ');}


Not using long would result in 32-bit integers in most platforms<; also, C++'s iostream library with their std:: namespace are more verbose than C's I/O. (edit - I stand corrected, this is not true)

Update (-9 bytes): Learnt that return was optional in C++ thanks to @anatolyg

• Actually, I get exactly the same character count with cstdio as with iostream. Also, C++ doesn't require return 0. Apr 27, 2016 at 14:46
• Thanks for the tip regarding return; also adding an iostream version, as you are again right - same byte count. Apr 27, 2016 at 16:23

# Common Lisp, 39 bytes

Disclaimer: I'm not responsible for any traumatic effect caused by the extreme density of parentheses. It's the language specification's fault. This one has surprisingly few parentheses!

(loop for a from 1 to(read)do(write a))


# Brachylog, 7 bytes

:1:efrw


or alternatively

:1:efr.


# Python 3, 43 42 bytes

x,i=int(input()),0
while i<x:i+=1;print(i)


Explained line-by-line:

x,i=int(input()),0
x  =int(input())   # Convert string input to integer, then assign x to it
,              ,  # Separate variables
i=             0 # Assign i to 0

while i<x:i+=1;print(i)
while    :              # Enter a WHILE loop
i<x               # Set limit
i+=1          # Count up
;         # Separate statements
print(i) # Print number


Old answer below. Hopefully this one will be able to count up to incl. 2**64-1.

# Python 3, 41 bytes

for n in range(1,int(input())+1):print(n)


Ungolfed

for number in range(1, int(input()) + 1):
print(number)


Explained for those who can't understand

for n in range(1,int(input())+1):print(n)  # Code
for n in                        :          # Initiate a for loop with n as the number
range( ,              )           # The list of numbers we want to output in order
input()               # We get n from string input
int(       )              # We convert the input to integer
+1            # We add one to the range 'cause we want to include n
print( )   # We then output
n    # n is what we output

• This won't work for all 64-bit integers, so it is invalid by your own rules. Apr 26, 2016 at 18:07
• I think it works (language limit). If there is a way to make it work up to 2^64-1, please tell me. Apr 26, 2016 at 18:38
• You can use xrange(). Note: even xrange() may have issues, at least in 2.7.10. Apr 26, 2016 at 19:06
• I used it in my (sadly, shorter) Python 2 answer. Apr 26, 2016 at 19:07
• @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ as you only use your input once, you can just do while i<int(input)) . Also in your older version at 41 bytes, by removing the 1, in you range and the add 1 after the input, and placing either +1 after or -~ before the n in the print, it will be shorter and get the same answer. Also can I ask why your older answer is shorter, but you're not using it? Jun 15, 2016 at 17:45

# UGL, 14 11 bytes

ic^l_u$ocO^^-: il$d:_locO:


Uses U+0000 as delimiter.

Try it online!

Try it online! (14-byte version)

### Explanation

This builds [9,8,7,6,5,4,3,2,1] for an input of 9, and then print them all out (with U+0000 as separator).

### Explanation for 14 bytes

ic^l_u$ocO^^-: i # n = input() c # i = 0 ^l_ ^^-: # while i ~= n: u$o        #     print(i++)
cO      #     print(chr(0))


## PHP, 2623 31 bytes

<?=join(' ',range(1,$argv[1])); // 31 if using N isnt allowed <?=join(' ',range(1,$n)); // 25 if using $n is allowed <?=join(' ',range(1,N)); // 24 bytes, join() is an alias of implode() <?=implode(' ',range(1,N)); // 27 bytes  "You can get n any way" -> In this case, N is a constant. Edit: Apperantly "any way" isn't "any way", it now takes commandline arguments • Hardcoding inputs is not allowed by default, and the author does not override that default (as you can see from this comment). – user45941 Apr 26, 2016 at 9:33 • Updated accordingly Apr 26, 2016 at 9:55 • @Mego You are correct, I clearly state you must get n. I didn't do any override. Apr 26, 2016 at 10:48 • Which I interpretted as "I get N from a constant" ;) But, changed my answer to the proper interpretation Apr 26, 2016 at 12:30 • Isn't the statement-ending semicolon required? Omitting it on an online PHP codepad gives Fatal error: syntax error, unexpected$end, expecting ',' or ';' Apr 27, 2016 at 4:05

# Dip, 1 - .2 = .8

l


Body must be at least 30 characters; you entered 13.

• Can you provide a link to a Dip interpreter? I can´t find any reference to that language on the web. Jul 7, 2017 at 15:20
• It was my language but i deleted it Jul 8, 2017 at 16:24

## C#, 10511710910710199 59 bytes

Golfed

void m(ulong u){while(u>=0)System.Console.WriteLine(u--);}


Ungolfed

void m( ulong u ) {
while (u >= 0)
System.Console.WriteLine(u--);
}


Releases

• v3.0 - -40 bytes - Changed the output to directly print to the console with a new line at the end. This update allows the usage of ulong. Once again, this is thanks to hstde.
• v2.4 -  -2 bytes - Replaced long with int due to the limitations of the capacity of List<T>, which is capped to the max of Int32.MaxValue in the implementation. The reason for changing to int can be found here. You can also explore this limitation in Reference Source.
• v2.3 -  -6 bytes - Using var instead of List<long>. Thanks to hstde.
• v2.2 -  -2 bytes - Fixed the decrements of the counter and removed brackets.
• v2.1 -  -8 bytes - Update to use the argument, making the code shorter and faster.
• v2.0 - +12 bytes - Update to List<> since arrays max size is Int32.MaxValue == 2 ^ 32 - 1
• v1.0 - 105 bytes - Initial release
• You're still gonna have a problem with anything bigger than int.MaxValue. But you can still shave off some bytes by replacing List<long>l with var l Nov 8, 2016 at 10:46
• @hstde Unfortunately, as far as I know, the Array and List object in the .Net have a limitation of Int32.MaxValue ( 2 147 483 647 ) items. Although I haven't explore this fully, for what I've read you would most likely ran out of memory than hit the limitation of the objects. Please, correct me if I'm wrong. Nov 9, 2016 at 14:41
• I played around a little and you indeed get an out of memory exception even when using something other then List<>. So the correct implementation would be an iterative from 0 to c. Nov 9, 2016 at 14:57
• Even if I was able to implement a way to count up to the Int64.MaxValue - which is required by the challenge - I would hit the size limit of the String, which is Int32.MaxValue. Nov 9, 2016 at 15:14
• You are right. That's why I need to learn to read... Nov 10, 2016 at 17:47

# Labyrinth, 412923 14 bytes

?}):
\ !
@"({


Try it online!

Takes the input number and moves it to the auxiliary stack and increments an implicit zero on the main stack. Repeatedly duplicates the top of the stack, outputs the number, moves a copy of the input number from the aux stack and decrements it. If that number is zero, the program exits. Otherwise it outputs a newline and continues the loop.

# LibreLogo, 35 bytes

Code:

print set range 1 (int (input ")+1)


Input:

Output:

# Taxi, 1,264 bytes

Line breaks are not required so here's the golfed version:

Go to Post Office: w 1 l, 1 r, 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: s 1 l, 1 r.Pickup a passenger going to Sunny Skies Park.Go to Sunny Skies Park: n 1 l, 1 l, 1 r.[a]1 is waiting at Starchild Numerology.Go to Starchild Numerology: s 3 l.Pickup a passenger going to Addition Alley.Go to Go More: e 1 l.Go to Addition Alley: w 1 r, 3 r, 1 r.Pickup a passenger going to Cyclone.Go to Cyclone: n 1 l, 1 l.Pickup a passenger going to Cyclone.Pickup a passenger going to The Babelfishery.Go to The Babelfishery: s 1 l, 2 r, 1 r.Pickup a passenger going to Post Office." " is waiting at Writer's Depot.Go to Writer's Depot: n 1 l, 1 l, 2 l.Pickup a passenger going to Post Office.Go to Post Office: n 1 r, 2 r, 1 l.Go to Cyclone: s 1 r, 1 l, 2 r.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Equal's Corner.Go to Sunny Skies Park: n 1 r.Pickup a passenger going to Cyclone.Go to Cyclone: n 1 l.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Equal's Corner.Go to Sunny Skies Park: n 1 r.Pickup a passenger going to Addition Alley.Go to Equal's Corner: s.Switch to plan "b" if no one is waiting.Go to Taxi Garage: n 3 r, 1 r, 2 l, 2 r.[b]Go to Sunny Skies Park: n.Switch to plan "a".


And the formatted version for humans:

Go to Post Office: w 1 l, 1 r, 1 l.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: s 1 l, 1 r.
Pickup a passenger going to Sunny Skies Park.
Go to Sunny Skies Park: n 1 l, 1 l, 1 r.
[a]
1 is waiting at Starchild Numerology.
Go to Starchild Numerology: s 3 l.
Pickup a passenger going to Addition Alley.
Go to Go More: e 1 l.
Go to Addition Alley: w 1 r, 3 r, 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone: n 1 l, 1 l.
Pickup a passenger going to Cyclone.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery: s 1 l, 2 r, 1 r.
Pickup a passenger going to Post Office.
" " is waiting at Writer's Depot.
Go to Writer's Depot: n 1 l, 1 l, 2 l.
Pickup a passenger going to Post Office.
Go to Post Office: n 1 r, 2 r, 1 l.
Go to Cyclone: s 1 r, 1 l, 2 r.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Equal's Corner.
Go to Sunny Skies Park: n 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone: n 1 l.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Equal's Corner.
Go to Sunny Skies Park: n 1 r.
Pickup a passenger going to Addition Alley.
Go to Equal's Corner: s.
Switch to plan "b" if no one is waiting.
Go to Taxi Garage: n 3 r, 1 r, 2 l, 2 r.
[b]
Go to Sunny Skies Park: n.
Switch to plan "a".


I can't find any documentation on integer limits, but my testing seems to show that Taxi can handle up to 64 bit signed integers but not un-signed. That means it can only count up to (2^63)-1.

# Stax, 1 byte

m


Run and debug online!

Added for completeness. That's it. Stax does it in 1 byte.

# Pepe, 30 25 bytes

That's an amazing score for Pepe!

And now, I've saved 5 bytes because of the "flags" update. Now, instead of duplicating the item, I can set a flag to not remove it.

Also, Pepe seems to beat few practical languages now.

REeEREErEEEEErreEEreeERee


Try it online

This challenge made me rethink the control flows in Pepe. It helped me realize that I've created them completely wrong, so I remade them. ¯\_(ツ)_/¯ Thanks!

Warning: If you don't give any input or it will be smaller than 0, your browser will die.

Don't know if the bonus applies, if int's in JS support these numbers, then yes, otherwise no. My PC is not strong enough to print this large number in HTML.

## Ungolfed:

REeE
REE
rEEEEE
r reEE
reeE
Ree


## Explanation:

• REeE - Input number to stack R
• REE - Define label input
• rEEEEE - Increment item in stack r
• rEEEeE - Duplicate item in stack r
• r reEE - Pop Get value from stack r and print popped item as number - Flag r prevents removal of the item
• reeE - Output newline
• Ree - Goto label input if selected items in both stacks are equal

Basically, loop until the certain value is reached.

# Brain-Flak, 14 bytes

{(({})[()])}{}


Try it online!

simply pushes the top stack value -1 until it reaches 0. Then it pops the zero and implicitly prints the stack

# MAWP 1.0, 30 bytes

%@_1A[1A~25WWM~]~[!1A]%[:48W;]


Output takes a little while for larger numbers.

Try it!

# Flurry, 16 - 3.2 = 12.8 bytes

{}{<><<>()>[]}{}


### Run example

$./flurry -inn -c "{}{<><<>()>[]}{}" 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15$ ./flurry -inn -c "{}{<><<>()>[]}{}" 1
1


Generates the range using the stack height. Since the task requires 1-based, each stack height should be incremented (produce 2 when stack height is 1, 3 when stack height is 2, etc.).

main = {} f {}   -- n f 1
-- Apply f n times to the starting value of 1
f = {<><<>()>[]} -- \x. push(x); return (succ height)
-- Implicitly push the argument and ignore it,
-- returning the value of height + 1
-- so that it can be pushed at the next iteration


Flurry uses Church numerals as the number representation, so it theoretically supports infinite-precision positive integers. But it will take a very long time to actually print the result.

# Thunno 2, 1 byte

R


Attempt This Online!

Pretty simple.

# Rockstar, 44 bytes

listen to N
X's 0
while N-X
build X up
say X


Try it here (Code will need to be pasted in)

# Desmoslang Assembly, 8 Bytes

[1...IOT


Explanation: The ending bracket is automatically added, you can output lists, and [1...x] creates a list counting 1 through x.

# (,)352 243 Chars or $$\243\log_{256}(3)\approx48.14\$$ Bytes

(()(),()()()()()()())(,(((),(())(),,,(()()())()(),(())(()(),,,,(),,(()())))((()()),((()()),,,,(),,(()())()()())((),(,,,,,())))((),(())(),,,((()())),(())())((()()),((),(,,,,,())))),,,(,(()()(),((()))))(()()()),())(,,()((),(())()),,(),,((()())))


TIO

If we can take input in unary, 27 Chars or $$\27\log_{256}(3)\approx\$$5.35 Bytes:

(,,((),(())())(),,((()())))


TIO

## C++, 91 bytes

### Golfed:

#include<iostream>
int main(){int c;std::cin>>c;for(int x=1;x<=c;x++){std::cout<<x<<"\n";}}


### Ungolfed:

#include<iostream>
int main(){
int c;
std::cin>>c;
for(int x = 1; x <= c; x++){
std::cout<<x<<"\n";
}
}

• No C++ expert, but I think that int must return something. Apr 25, 2016 at 16:49
• Actually, no. The 'return 0' is implied by almost all modern compilers. Apr 25, 2016 at 17:04
• does std::cin>>c work i though it would cause type cast error char* to int... Apr 26, 2016 at 1:11
• @MartinBarker That error only occurs if the user inputs something other than an int. Apr 26, 2016 at 3:13
• You can declare x together with c to spare the second use of int, no need for the braces around a single instruction after for, you can increment x when outputting it so not need to mention it again inside for. At least g++ 5.2.1 accepts this (of course, after the include): int main(){int c,x;std::cin>>c;for(x=1;x<=c;)std::cout<<x++<<"\n";}. Apr 26, 2016 at 7:29

# TI-Basic, 11 bytes

For(I,1,Ans:Disp I:End


I would do seq(I,I,1,Ans for 8 bytes but lists can't support 2^64 elements

• Could you support 2^64-1 with seq(I,I,1,Ans? Apr 26, 2016 at 8:17
• @ΈρικΚωνσταντόπουλος Yes, as a single element, but the entire sequence would exceed the 999 element limit for a list, and exceed the calculator's memory. Apr 26, 2016 at 18:41
• Then keep your 11-keystroke solution. Apr 26, 2016 at 18:42

# Bash, 34 Bytes

for ((i=1;i<=$1;i++)); { echo$i;}


Split answer from GNU coreutils, this is pure bash.

• for((;i++<$1;));{ echo$i;} - 27 bytes. But bash uses 64 bit signed integers, so this will only go as far as 2^31 - 1 Apr 25, 2016 at 17:54
• That's the limit for 32 bit integers, not 64. Apr 26, 2016 at 5:31
• @DigitalTrauma 64-bit integers meet the spec (2^64-1), 32-bit ints don't. It's fine, though. Apr 26, 2016 at 8:19
• The sign uses one of the 64 bits (not half of them!), so bash's maximum is 2^63-1 (empirically verified). Apr 26, 2016 at 14:39
• @CatsAreFluffy ha - of course I meant 2^63-1. 2^31 is an old force of habit I suppose. Still doesn't meet the spec IMO. Apr 26, 2016 at 14:57

# PGP, 28 Bytes

PHP Golf Processor (https://github.com/barkermn01/PGP-php-CodeGolf/) to run it php pgp.php file.pgp or php pgp.php '{code here}'

f(;$i!=$argv[1];)e ++$i." ";  • Can't you remove the space? e ++ Apr 29, 2016 at 17:49 • Not yet, your welcome to code it it in and send me a pull request :) Apr 30, 2016 at 21:16 • how about f(;$i++!=$argv[1];)e"$i ";? Jul 26, 2016 at 1:38

# Molecule, 10 bytes

0{1+~}InL.


Explanation:

0{1+~}InL.
0          Push 0
{1+~}     Create a code block
In   Ask the amount of times to repeat
L. Loop the code block n times and clean the stack.
`