# 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. – Martin Ender Apr 25 '16 at 12:20
• "You can get n any way." Does that mean we can assume n to be saved in a variable? – flawr May 21 '16 at 20:50
• @flawr You can get n any way. You can save it in a variable, but it must not be hardcoded. – Erik the Outgolfer May 22 '16 at 10:26
• It might be useful to link to the accepted I/O methods – Ephphatha Jun 2 '17 at 12:26
• @Ephphatha Yes it probably is, this challenge is from the old times where I was an utter newb. – Erik the Outgolfer Jun 2 '17 at 12:29

# 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. – anatolyg Apr 27 '16 at 14:46
• Thanks for the tip regarding return; also adding an iostream version, as you are again right - same byte count. – tucuxi Apr 27 '16 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. – Dennis Apr 26 '16 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. – Erik the Outgolfer Apr 26 '16 at 18:38
• You can use xrange(). Note: even xrange() may have issues, at least in 2.7.10. – user48538 Apr 26 '16 at 19:06
• I used it in my (sadly, shorter) Python 2 answer. – user48538 Apr 26 '16 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? – george Jun 15 '16 at 17:45

# Turing Machine Simulator - 1366 Bytes (124 Lines)

0 * * r 0
0 _ , r 1
1 _ 1 r ,
, _ , l 2
2 * * l 2
2 , * l 3
3 _ * r 4
3 1 0 l 4
3 2 1 l 4
3 3 2 l 4
3 4 3 l 4
3 5 4 l 4
3 6 5 l 4
3 7 6 l 4
3 8 7 l 4
3 9 8 l 4
3 0 9 l 3
4 * * l 4
4 _ * r 5
5 0 _ r 5
5 , * * n
5 * * r 6
6 * * r 6
6 , * r 9
9 * * r 9
9 _ * l z
z * * l m
m * * l m
m , * r 7
7 * * r 7
7 , * * x
7 0 p r p
7 1 q r q
7 2 w r w
7 3 e r e
7 4 r r r
7 5 t r t
7 6 y r y
7 7 u r u
7 8 i r i
7 9 o r o
8 * * l 8
8 , * l m
p * * r p
p . * r P
p _ . r P
P * * r P
P _ 0 l 8
q * * r q
q . * r Q
q _ . r Q
Q * * r Q
Q _ 1 l 8
w * * r w
w . * r W
w _ . r W
W * * r W
W _ 2 l 8
e * * r e
e . * r E
e _ . r E
E * * r E
E _ 3 l 8
r * * r r
r . * r R
r _ . r R
R * * r R
R _ 4 l 8
t * * r t
t . * r T
t _ . r T
T * * r T
T _ 5 l 8
y * * r y
y . * r Y
y _ . r Y
Y * * r Y
Y _ 6 l 8
u * * r u
u . * r U
u _ . r U
U * * r U
U _ 7 l 8
i * * r i
i . * r I
i _ . r I
I * * r I
I _ 8 l 8
o * * r o
o . * r O
o _ . r O
O * * r O
O _ 9 l 8
x * * r x
x _ , l b
b . 1 l c
b 0 1 l c
b 1 2 l c
b 2 3 l c
b 3 4 l c
b 4 5 l c
b 5 6 l c
b 6 7 l c
b 7 8 l c
b 8 9 l c
b 9 0 l b
c * * l c
c _ * r v
v * * r v
v , * * 2
n * * r n
n _ * r halt
n , _ r n
n . _ r n
n p 0 r n
n q 1 r n
n w 2 r n
n e 3 r n
n r 4 r n
n t 5 r n
n y 6 r n
n u 7 r n
n i 8 r n
n o 9 r n


You can try it out here - link Just set the initial input to the upper limit.

Supports arbitrarily large integers

• Where is the spec for this language? – Erik the Outgolfer Jul 19 '16 at 17:05
• @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ It should be a the bottom of the page in the link – KoreanwGlasses Jul 19 '16 at 17:06
• Not the syntax, the states, what they mean, etc. – Erik the Outgolfer Jul 19 '16 at 17:08
• @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Is this what you're looking for? en.wikipedia.org/wiki/Turing_machine#Informal_description – KoreanwGlasses Jul 19 '16 at 17:16
• No, i wouldn't have asked if it was there. I don't mean the syntax, or how the states work, I mean what the states are. – Erik the Outgolfer Jul 19 '16 at 18:09

# 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). – Mego Apr 26 '16 at 9:33 • Updated accordingly – Martijn Apr 26 '16 at 9:55 • @Mego You are correct, I clearly state you must get n. I didn't do any override. – Erik the Outgolfer Apr 26 '16 at 10:48 • Which I interpretted as "I get N from a constant" ;) But, changed my answer to the proper interpretation – Martijn Apr 26 '16 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 ';' – nickb Apr 27 '16 at 4:05

# Python 3, 31 bytes

print(*range(1,int(input())+1))


Outputs the range of numbers space-separated. Uses * operator magic to explode the output of range into separate arguments to print, which separates its arguments with spaces by default.

# 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. – Titus Jul 7 '17 at 15:20
• It was my language but i deleted it – Oliver Ni Jul 8 '17 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 – hstde Nov 8 '16 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. – auhmaan Nov 9 '16 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. – hstde Nov 9 '16 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. – auhmaan Nov 9 '16 at 15:14
• You are right. That's why I need to learn to read... – auhmaan Nov 10 '16 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.

## QBIC - non-competing, 6 bytes

:[a|?b


Start a FOR-loop ranging from 1 (default start of FOR-loops) to a, where a is read by : from the command line parameters. At every iteration, b (our FOR-loop counter) is printed (?).

# Stax, 1 byte

m


Run and debug online!

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

## 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. – Erik the Outgolfer Apr 25 '16 at 16:49
• Actually, no. The 'return 0' is implied by almost all modern compilers. – Michelfrancis Bustillos Apr 25 '16 at 17:04
• does std::cin>>c work i though it would cause type cast error char* to int... – Martin Barker Apr 26 '16 at 1:11
• @MartinBarker That error only occurs if the user inputs something other than an int. – Michelfrancis Bustillos Apr 26 '16 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";}. – manatwork Apr 26 '16 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? – Erik the Outgolfer Apr 26 '16 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. – Timtech Apr 26 '16 at 18:41
• Then keep your 11-keystroke solution. – Erik the Outgolfer Apr 26 '16 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 – Digital Trauma Apr 25 '16 at 17:54
• That's the limit for 32 bit integers, not 64. – CalculatorFeline Apr 26 '16 at 5:31
• @DigitalTrauma 64-bit integers meet the spec (2^64-1), 32-bit ints don't. It's fine, though. – Erik the Outgolfer Apr 26 '16 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). – joeytwiddle Apr 26 '16 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. – Digital Trauma Apr 26 '16 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 ++ – Erik the Outgolfer Apr 29 '16 at 17:49 • Not yet, your welcome to code it it in and send me a pull request :) – Martin Barker Apr 30 '16 at 21:16 • how about f(;$i++!=$argv[1];)e"$i ";? – Titus Jul 26 '16 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.


# Ruby, 18 12 bytes

->n{p *1..n}


-3 bytes from Not that Charles, and -3 more from daniero

• Can't you remove that space? – Erik the Outgolfer Apr 27 '16 at 13:14
• @ΈρικΚωνσταντόπουλος No. if i do it will try to multiply. – MegaTom Apr 27 '16 at 15:10
• Oh 13 more to go... – Erik the Outgolfer Apr 27 '16 at 15:41
• You can use p instead of puts – daniero Apr 29 '16 at 11:56

# Scratch, 12 10 bytes

(scoring used)
Asks for the end number, resets, and counts up.

• Finally an answer! – Erik the Outgolfer May 20 '16 at 14:51
• Scratch projects are meant to run multiple times. – weatherman115 May 20 '16 at 15:24
• See my remix – Erik the Outgolfer May 20 '16 at 15:34
• Well, you can golf it more: 1) Replace ask[\]]and wait with ask[]and wait for -1 point 2) To conform with the rules, you must say[] or say[]for()secs each and every number ("think" is considered STDERR for this challenge). So instead of add(c)to[list v use say(c 3) Since you do not need the list anymore you can remove the delete(all v)of[list v block for another -1 point. so you save a total of 2 points, resulting 10 points (both versions) – Erik the Outgolfer May 20 '16 at 15:37
• scratchblocks – Erik the Outgolfer May 21 '16 at 13:14

# Tellurium, 6 bytes

[I|+^]


This code runs a loop for an amount of times specified by the user (I). + adds one to the cell's value and ^ outputs the value.

# Desmos, 60+table bytes

l=\left[1,2,...,\operatorname{floor}\left(a\right)\right]
a=0


I have a set to 0 because the table would contain extra spaces if I didn't. That said, there isn't currently scoring for the table, which I've asked about on meta.

# PyCal, 6 bytes

*i[+^]


This runs the code +^ for n times.

+ adds one to the variable and ^ outputs the variable's value. Simple enough.

EDIT: Interestingly enough, this solution is the exact same length as my Tellurium (another esoteric language I made) solution.

# Python 2, 36 bytes

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


## Explanation

### Line 1

i=0 Generate the accumulator

### Line 2

x=input() Store the number

### Line 3

while Loop i<x while the accumulator is smaller than the number.

### Line 3.1

i+=1 Increment the accumulator.

### Line 3.2

print i Print the accumulator.

# PureData, 462 bytes

As file:

#N canvas 778 126 591 616 10;
#X obj 136 137 until;
#X obj 175 177 f;
#X obj 258 160 + 1;
#X obj 352 194 + 1;
#X msg 215 126 0;
#X obj 393 211 log/normal;
#X obj 215 96 moses;
#X obj 215 66 - 1;
#X msg 136 49 1.84467e+019;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 1 1;
#X connect 3 0 5 0;
#X connect 3 0 6 1;
#X connect 4 0 1 1;
#X connect 6 0 4 0;
#X connect 6 0 0 1;
#X connect 7 0 6 0;
#X connect 8 0 0 0;
#X connect 8 0 7 0;


Actual program, because it's a graphical programming language:

Note: Do NOT run it with this value as it will run for a very long time!

• moses? 18446744073709551615? Did you really have to impose that limit explicitly? – Erik the Outgolfer Jul 19 '16 at 19:23
• moses will part the sea, in this case it works like an if statement, if the left inlet's value is less than the right inlet's value it will send a bang through it's left outlet. I couldn't find any standard input like object in it, so you have to write your input number into that message box and click on it so the program starts. – Gábor Fekete Jul 19 '16 at 19:28
• Is this a joke language? moses will part the sea? Sounds religious to me... – Erik the Outgolfer Jul 19 '16 at 19:34
• puredata or pd is a discontinued visual programming language mostly for processing and generating sound. moses distributes the input value through it's outputs. – Gábor Fekete Jul 19 '16 at 19:38

## Emacs Lisp, 39 bytes

(lambda(n)(princ(number-sequence 1 n)))


# Jellyfish, 5 bytes

p>ri


Try it online!

### Explanation

p         >         r     i
print(each_increment(range(input)))


## C#, 47 bytes

l=>{for(int i=1;i<=l;)Console.WriteLine(i++);};