# 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

# 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++);};


# Mouse-2002, 47 bytes

?1(&DUP " "!&DUP &ROT &DUP &ROT =[0^]&SWAP 1+)$ I do not know how to replace &DUP &ROT &DUP &ROT ...&SWAP, it's intended to duplicate the two top elements of the stack (...A B → ...B A A B), perform an operation on them, and then restore the stack to what it was before (...A B). Here is the explanation: • ? pushes a number (base 10) from input (... → ... <input num>) • 1 pushes 1 (... → ... 1) • ( starts an infinite loop • &DUP duplicates the ToS (... A → ... A A) • " " prints   • ! prints the ToS as a number (... A → ...) • &DUP duplicates the ToS (... A → ... A A) • &ROT rotates the top three stack elements (... A B C → ... B C A) • &DUP duplicates the ToS (... A → ... A A) • &ROT rotates the top three stack elements (... A B C → ... B C A) • = checks if the ToS and the SToS are equal • [ skips to the matching ] if the ToS is not positive • 0 pushes 0 (... → ... 0) • ^ breaks out of the innermost loop if the ToS isn't positive (... A → ...) • &SWAP swaps the top two stack elements (... A B → ... B A) • 1 pushes 1 (... → ... 1) • + adds the top two stack elements (... A B → ... A+B) • ) closes the innermost loop • $ terminates the program

# R, 35 bytes

This statistician's language also has a scan() function, but requires information about how many characters it will receive, and providing a value for that would either limit the highest possible x, or require a very, very long argument.

for(x in 1:readline()){cat(x,'\n')}

# SQL, 108 Bytes

Golfed:

CREATE PROCEDURE C @n INT AS BEGIN DECLARE @a INT;SET @a=1;WHILE @a<=@n BEGIN PRINT @a;SET @a=@a+1;END;END
GO


(It fails if I put it all on one line!)

Ungolfed:

CREATE PROCEDURE C
@n INT
AS
BEGIN
DECLARE @a INT;
SET @a=1;
WHILE @a<=@n
BEGIN
PRINT @a;
SET @a=@a+1;
END;
END
GO


Usage:

EXEC C 5


Output:

1
2
3
4
5


# C++, 89 83-20%=66.4 bytes

#include<iostream>
auto f=[](auto n){for(decltype(n)i=0;i++<n;)std::cout<<i<<",";};


Should work for up to 2^64-1

# R, 3 bytes

seq


A built-in function that, when given a single positive integer n as argument, yields 1 to n.

# D, 55 bytes

(ulong n){import std.stdio;foreach(i;1..n+1)i.writeln;}


# GameMaker Language, 38 bytes

for(i=0;i<argument0;show_message(++i))

• Couldn't you do for(i=0;i<argument0;show_message(++i)) for -3 bytes? – Erik the Outgolfer Jun 18 '16 at 9:39
• I suppose, thanks for the tip. – Timtech Jun 18 '16 at 21:00

## ><> (Fish), 16 bytes

Solution 1

01+:{:?!;1-rnao!


Try it here!

Solution 2

01+::{:{(?;rnao!


Solution 3

0\
o>1+::{:{(?;rna


Wow can't believe I don't see any ><> submissions, have 3! All the solutions are 16 bytes, just structured differently (the top one would be my "real" submission I guess). Simply place n on the stack and away you go!

## Basic Explanation

0                push 0 to the stack
:             copy the result
{            shift stack left
:           copy n
?!;        if n is 0, end
1-      subtract 1 from n
r     reverse the stack
n    output a number
ao  output a newline
! skip the next instruction (0)


## Long Explanation

As I made these in reverse order, I'll explain them in reverse order (probably be easier to follow)... These programs are pretty simple, I invite you to check out what the instructions do here.

Explanation 3

0\
>


This simply places 0 onto the stack (let's call it x), then tells the fish to move downwards, then to the right. We now have [n, x] on the stack, we'll place _s before temporary versions of these variables.

The fish immediately must swim over 1+:: which adds 1 to x and then duplicates it twice, giving us the stack of [n, __x, _x, x]. {:{ shifts the stack to the left, copies n (because it's now on the end of the stack), then shifts the stack left again giving us [_x, x, n, _n, __x].

Now the fish must figure out (?;, which starts with (. ( pops _n and __x off the stack and checks to see if _n is less than __x, pushing 1 to the stack if so, and 0 otherwise. Then ?; pops that result off the stack, executing ; (end of program) if it found a 1, and skipping over ; otherwise. This will end up with a stack of [_x, x, n].

If the fish continues forwards it will encounter rnao because of the wrap-around, this simply tells the fish to reverse the stack, putting _x at the front of the stack, then outputting it as a number with the instruction n. ao simply places a newline on the stack (character 10 or a), and then outputs it.

That's it!

Explanation 2

This is pretty much the same as Explanation 3. It doesn't have the fish mirror/movement instructions because it's only one line. It can do this because the ! at the end of the line causes the fish to skip the 0 at the beginning during the wrap-around.

Explanation 1

This solution is slightly different. I was hoping to save some bytes (you can see I didn't).

You can see it deviates pretty early with :{:, instead of copying x twice in the beginning I only do it once, then I only do one stack shift left instead of two.

I also don't use (?; and instead use ?!;, this is because n is actually being decremented each loop instead of just being compared to x. The ! is because ? actually does the opposite of what we want compared to before, so we invert its behaviour by executing ! when n>0, skipping the ;. Then the fish swims over 1- which simply subtracts 1 from n, and the program carrys on the same as the others!

# Ruby, 12 bytes

Lambda. Splats a range and prints that. Try it online!

->n{p *1..n}


EDIT: I can't personally confirm that this counts up to 2^64-1, since it runs out of memory, but I believe Ruby uses bigints. If someone can confirm this, the score with bonus is 9.6.

# Silicon, 3 bytes

1I\


1 pushes... well, 1.

I gets input and converts it to an integer before pushing it onto the stack.

\ takes the two top stack items and runs it through the Python range() function.

Output is implicit.

# Java, 163 (163 - 20% = 130.4, not sure if applies for bonus) bytes

enum h{;public static void main(String[]a){long i=1;while(Long.compareUnsigned(i,Long.parseUnsignedLong(a[0]))!=1)System.out.println(Long.toUnsignedString(i++));}}


Uses Java 8 functions to use unsigned longs which can store numbers up to 2^64-1(according to this page). Number is taken from first number

enum h {
;

public static void main(String[] a) {
long i = 1;                                                         // Counter
while (Long.compareUnsigned(i, Long.parseUnsignedLong(a[0])) != 1)  // While counter is smaller or equal to input
System.out.println(Long.toUnsignedString(i++));                 // Show counter as unsigned long(to be in correct range)
}
}


## REXX, 27 bytes

arg #
do i=1 to #
say i
end


Maximum number is dependent on NUMERIC DIGITS setting.

# Modified processing. 39-7.8 = 31.2 bytes

var n=0;for(var I=0;I<n;i++){print(I);}


Uses this version of processing. In practice it cannot do it all the way until the max number but it could in theory. Also a side note it did say input as any way I wanted and that input is replaced by n.

# Sinclair ZX80 BASIC, 4/8K ROM, ~38 bytes (4K ROM) listing

This was an edit of my initial entry, however there is a slight issue with it, which is explained below:

1 LET S=1
2 INPUT N
3 PRINT S,;
4 LET S=S+1
5 IF S<N+1 THEN GO TO 3


Whilst there is nothing wrong with the logic, when the ZX80's DFILE (or screen) is full, the program will halt and you will be returned to direct mode, which will show your program listing.

In order to get around this, press T on the ZX80's 'keyboard' and, on the 4K ROM version at least, the command CONTINUE should appear. Press NEW LINE and the program will continue where you left off. You can only do this once you have returned to direct mode though.

As you may know, a ZX80 with an 'old ROM' (original 4K ROM) will only handle 16-bit signed integers so the range is limited and I'm not going to win the bonus points. If you enter a number <1 then it will print 1 then exit.

This will work in other variants of Sinclair and 8-bit BASIC. On the ZX Spectrum though, this can be done in just two lines, like:

1 LET s=1: INPUT n
2 PRINT s,;: LET s=s+1: IF s<=n THEN GO TO 2


Using a FOR..NEXT loop will condense the program further to just one line.

Fortunately, the Spectrum, like all other more sane 8-bit personal computers, allows <= and >= in your conditions. If the 4K ROM ZX80 allows this, I've not found out how to do it yet.

• The challenge is about counting from 1 to n, not from n to m, so you only have one input. Also, input prompts are unneeded. I think you can also remove CLS. – Erik the Outgolfer Mar 29 '17 at 15:24

# Newline NC 23 bytes

g\n[\nd\nq\np\ni\n|\na\n0\ng\n]


\nis a newline. Try it online Input is in the variable numbers, that is STDIN for newline.

• Why can't you just use multiple lines for newlines? – hyper-neutrino May 30 '17 at 3:30
• @HyperNeutrino uhhhh idk takes up way to much space to view i guess – Christopher May 30 '17 at 12:29
• Okay. This way looks a bit unclear but up to you. – hyper-neutrino May 30 '17 at 12:57
• @HyperNeutrino it is also how the current interpreter works – Christopher May 30 '17 at 13:02
• Ah. Okay. Makes sense. Thanks for clarifying. – hyper-neutrino May 30 '17 at 13:08

# Japt, 1 byte

Outputs an array of integers.

õ


Try it online

# JavaScript (ES6), 32 bytes

Outputs an array of integers

n=>[...Array(n)].map((_,y)=>++y)


## Try It

f=
n=>[...Array(n)].map((_,y)=>++y)
oninput=_=>o.innerText=f(+i.value)
o.innerText=f(i.value=6)
<input id=i min=1 type=number><p id=o>

# Braingolf v0.7, 14 bytes

UV# R&,{_v!@R}


### Explanation:

UV# R&,{_v!@R}  Implicit input of n
U               Replace stack with ascending range 1-n
V#<space>      Create new stack, switch to it and push space character
{.....}  Foreach/Map loop, runs for each item in stack
_       Pop and output last item on stack
v!@    Switch to next stack and print a space


# Rust, 35 bytes

|n|for i in 0..n{print!("{} ",i+1)}


An anonymous function that does the task described. It can be one byte shorter if an inclusive range was used, but that's currently unstable. It is able to count to 2^64-1 (provided you call it with an u64 as argument).

# Whitespace, 50 * 0.8 = 40 bytes (assumes n is on the stack)





Try it online!

This code assumes n is already on the stack as it saves bytes over taking it from STDIN. The TIO link has a header provided to take n from STDIN so it can be tested more easily. An extra no-op command (stnn ; slide 0) has been added to the header to work around a TIO quirk where a newline gets introduced when the sections are concatenated.

Whitespace numbers are arbitrary precision so this program exceeds the upper limit specified in the question. This uses a fixed number of stack elements so will not run into memory limits either.

## Explanation

(s - space, t - tab, n - newline)

; The first four instructions are provided as a convenience to get input
;  from STDIN and leave it on the stack
sssn  ; push 0
sns   ; dup
tntt  ; getnum - read number from stdin and save at address 0
ttt   ; retrieve value from address 0 and place on the stack

; bytecount starts here
sssn  ; push 0 - initialise i
nssn  ; loop:
ssstn ; push 1
tsss  ; add - increment i
sns   ; dup
tnst  ; putnum - display i as a number
sssn  ; push 0 - use null byte as a separator, shortest constant
tnss  ; putchar - display null byte, often displayed as a space
sns   ; dup - copy i
stsstsn ; copy 2 - copy n
tsst  ; sub - calculate i-n
nttn  ; jlz "loop" - continue looping if i < n


# MY, 3 * 0.8 = 2.4 bytes

Here's the hex:

1A 49 27


Explanation:

1A - Take input as an integer, then push to stack
49 - Pop n; Push [1 ... n]
27 - Pop n; Output n (with a trailing newline)


MY is written in Python, where integers have no size limit.

# Swift 3, 53 bytes

func c(n:UInt){var l:UInt=0;while l<n{l+=1;print(l)}}


Note: this only works on 64-bit devices. Here is a 32-bit device solution (57 bytes):

func c(n:UInt64){var l:UInt64=0;while l<n{l+=1;print(l)}}

• You only have to support natural upper limit. – Erik the Outgolfer Jun 30 '17 at 17:06

## Swift 3, 40 bytes

func f(n:UInt){for i in 1...n{print(i)}}


Uses Swift ClosedRange (1...n) type. Prints up to UInt maximum aviable

# cQuents, 2.4 bytes (3 bytes - 20%)

::$ Fairly simple, does exactly what the challenge wants. Since cQuents is implemented in Python, it works as long as Python integers can continue growing. Try it online! ### Explanation  Implicit input n :: Mode: Sequence 2. Output the sequence up to n$   Each item in the sequence is the current (1-based) index

• Note current version uses & instead of :: (saves a byte) – Stephen Feb 1 '19 at 4:50

# Retina, 18 bytes

+^1
$%'$n1
1+
\$.0


Try it online!

# Brainfuck, 24 bytes (-4.8 = 19.2)

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


Technically it can go as high as you want as long as you set your cell size high enough.

Also all I/O is in ascii.

How it works is first it takes input into the third cell, then it duplicates itself (self-destructively) into the next two cells, and taking one away from the second one, repeating that unit it reaches 0. Then, it prints 1 and then goes back two spaces and prints until it reaches the beginning, where we skipped two spaces so it would terminate.

• Does not seems to work... instead it prints the characters with the ascii from 1 to the ascii of the input character. – leo3065 Mar 15 '18 at 8:13
• Also all I/O is in ascii` – vityavv Mar 15 '18 at 10:57