# Print numbers from 1 to 10

This might be a very simple challenge, but I am surprised it hasn't been done on code-golf yet:

Print all Integers from 1 to 10 inclusive in ascending order to standard output.

Your output format can be whatever your language supports. This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), and prefixes and postfixes (like [...]). However, you may not output any other numbers than 1 through 10. Your program may not take any input. Standard loopholes are disallowed.

This is , so shortest answer in bytes wins!

• Related (duplicate?) – Luis Mendo Jul 21 '16 at 9:07
• If the only change is hard-coding a single parameter then that falls under the banner of "trivial change", and by the standards of this site still counts as a dupe. – Peter Taylor Jul 21 '16 at 9:54
• @PeterTaylor The other challenge has a huge problem with the integer limits though. The way it's specified every TC language that doesn't have 64-bit integers needs to implement them. (And that affects quite a lot of languages.) – Martin Ender Jul 21 '16 at 10:01
• @xnor Quite frankly, I'd rather close the other challenge as a duplicate of this one. The requirement pretty much ruins it. – Dennis Jul 21 '16 at 14:09
• I can't believe every single of the (currently) 71 answers assumes the base should be decimal… – Skippy le Grand Gourou Jul 22 '16 at 15:05

# Putt, 2 bytes

X:
X # Roman Numeral for 10
: # Ranger operator pushes [1..N]
# Putt implicitly prints

# Perl 5, 13 bytes

say for 1..10

### Example execution

perl -E 'say for 1..10'

# PHP (with goto) - 4638 34 bytes

More byte-saving suggestion from Shaggy:

<?php Z:echo@++$i;if($i<10)goto Z;

And people say that goto is the work of the Devil. Or something.

Try it online

### PHP (goto-less) - 30 29 bytes

<?php while(@$i<11)echo@$i++;

### PHP - 11 bytes

12345678910

• Save 4 bytes by replacing ten with a single character variable name and another 4 by removing the php . – Shaggy Jun 11 '19 at 11:43
• Thanks, then I won't have goto ten but anyways – Shaun Bebbers Jun 11 '19 at 15:41
• Why is the 11-byte version non-competing? This is a kolmogorov-complexity challenge; hardcoded answers are allowed. – pppery Sep 20 '19 at 23:27
• Okay I will amend if you say that I must. – Shaun Bebbers Sep 21 '19 at 10:13

# Hexadecimal Stacking Pseudo-Assembly Language, 54 bytes

203039400000120000201A8540000012000020000A400000120000

Try it online!

203039 input 0x3039 (decimal 12345)
400000 push that on stack
120000 print it
201A85 input 0x1A85 (decimal 6789)
400000 push that on stack
120000 print it
20000A input 0xA (decimal 10)
400000 push that on stack
120000 print it

# Poetic, 163 bytes

o,i admit i was a victim
i was tired of this situation
i couldnt be sicker of it
thats a very different outcome than i thought

Try it online!

Outputs the numbers from 1 to 10, separated by ASCII 0 (NUL) characters.

For being such a simple type of program, this was an interesting challenge to golf.

# Intcode, 49 bytes

4,15,1001,15,1,15,8,15,16,14,1006,14,0,99,-1,1,11

Why am I still doing this? Because it's fun. That's why.

# Wren, 28 bytes

System.write((1..10).toList)

Try it online!

## Explanation

System.write(              )  // Output
(1..10)          // Numbers from 1 to 10
.toList   // Converted to a list

# Intcode, 44 bytes

204,8,109,1,1205,8,0,99,1,2,3,4,5,6,7,8,9,10

Try it online!

Isn't it unfortunate that a just-hardcode solution outgolfs the other intcode answer by four bytes?

## Wz, 4 bytes

10aM

Just does a range from (implicit) 1 to 10.

## Spice, 55 bytes

My solution is posted as to the language spec, which currently fails because of an interpreter bug. To run against the interpreter the score falls to 63 bytes due to 2 NUL statements being required.

;a@ADD a 1 a;SWI a 10 0;LOD std::sort.spice ^a a;OUT a;

;a@NUL;NUL;ADD a 1 a;SWI a 10 2;LOD std::sort.spice ^a a;OUT a;

## Un-golfed Explanation

;a@          - declare variable 'a'
ADD a 1 a;   - ADD a[0] to 1 and insert at a[0], empty "a" implicitly 0
LOD std::sort.spice ^a a; - Use std lib to sort a 1->10
OUT a;       - Output a

# GolfScript, 6 bytes

It hasn't been done? Then great. Generates 0 to 10 and removes 0, then it evaluates.

11,1>

Try it online!

# naz, 50 bytes

1x1f1a1o2x1v0m9a1a1o1v0x1f1f1f1f1f1f1f1f1f8s1o1s1o

Explanation (with 0x commands removed)

1x1f                   # Function 1
1a1o               # Add 1 to the register and output
2x1v           # Store the new value in variable 1
0m9a1a1o   # Output a newline
1v # Read variable 1 into the register
1f1f1f1f1f1f1f1f1f     # Call function 1 nine times
8s1o                   # Subtract 8 and output
1s1o                   # Subtract 1 and output

# jq, 12 characters

(11 characters code + 1 character command line option.)

range(1;11)

Sample run:

bash-4.3$jq -n 'range(1;11)' 1 2 3 4 5 6 7 8 9 10 On-line test # Bc, 14 characters while(i++<10)i Sample run: bash-4.3$ bc <<< 'while(i++<10)i'
1
2
3
4
5
6
7
8
9
10

## JavaScript (using external library) (39 bytes)

x=>console.log(_.Range(1,10).Write(""))

Explanation of code: _.Range creates the array [1,..10], Write joins the array into a string, console.log puts to StdOut

• I was thinking about using something like Underscore's range, but figured something pure would be a bit more impressive. Nice solution! – Swivel Jul 21 '16 at 20:03
• Thanks! Yeah yours is way shorter than mine hahaha, I need to learn the ... syntax! – applejacks01 Jul 21 '16 at 20:31
• MDN has an article on the Spread Operator :) -- I started with [...Array(10)].map((v,i)=>++i), but that was 30 bytes and I was hoping to do better than the first JavaScript answer on here (24 bytes)! Then I realized that a String is, more or less, just an array of characters. So I tried the spread operator, and viola! – Swivel Jul 21 '16 at 20:36
• Ahhhh ok wow I see what its doing. Not bad!! – applejacks01 Jul 21 '16 at 20:40

# JavaScript (Node.JS 5 / Harmony / ES2015), 19 bytes

[...123456789`,10]

Output

[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]

Try it here or run node -p -e "[...'123456789',10]"

(For older versions of Node.js, like LTS 4.4.7, use node --harmony)

• Previous attempts were: [...Array(10)].map((v,i)=>++i) and [...Array(11).keys()].slice(1), but both ended up with 30 bytes, which was less than the other JavaScript submissions here. – Swivel Jul 22 '16 at 14:41
• 1) Your code does not print the integers; but as -p clearly adds functionality to it, there should be some penalty for it imo. 2) When I log that to my console (without node), I get an array with nine strings and one integer 3) This is pretty close to a hard coded result. – Titus Jul 22 '16 at 14:56
• There were both an [...Array(10)].map((_,i)=>i+1) and an [...Array(11).keys()].slice(1) elsewhere, just wrapped with alert making them 37 bytes – Paolo Bonzini Jul 22 '16 at 16:45
• @Titus (1) This is Node.JS, not browser-based JavaScript. They are two different things. However, I can kind of see your point with -p. (2) "This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), prefixes and postfixes (like [...])." (3) Arguable. – Swivel Jul 22 '16 at 20:05
• @PaoloBonzini You're late to the party. Both of those were posted by Titus four hours ago. Both of which I left in the comments here and on another answer roughly 24 hours ago :) Granted, I didn't put them in my solution, but that's beside the point. -- As for using an alert instead, I defer to (1) in my response to Titus. I primarily develop in Node.JS and use the Node.JS REPL, not browser-based JavaScript. These are two different platforms; similar implementations of a similar spec, but arguably not the same exact thing. I respect the position, though. – Swivel Jul 22 '16 at 20:10

# LibreLogo, 20 bytes

Code:

print set range 1 11

Output:

# Triangular, 15 bytes

S](l.U@..i/AS%<

Formats into this triangle:

S
] (
l . U
@ . . i
/ A S % <
1. The first command, S, stashes the top of stack (0) in memory. (This is only so that the U will work the first time.)
2. ( opens a loop.
3. U pulls memory onto stack.
4. i increments the stack value.
5. < directs the IP left, hitting %, which prints the top of stack as an integer.
6. S stashes the top of stack in memory.
7. A pushes 10 to the stack.
8. / directs the IP up-right, hitting @, which prints the top of stack (10) as ASCII (\n).
9. l checks if the second-to-last stack value (the counter value) is less than 10.
10. If so, jump back to (. Otherwise, exit the program.

# tcl, 23

time {puts [incr i]} 10

# ><>, 10 bytes

llnao:9=?;

Try it online!

### Explanation:

This program pushes the length of the stack instead of trying to increment the top of the stack, because l is shorter than 1+, and you can do it to an empty stack.

l             Push the length of the stack. The first time through pushes 0.
ln           Print the length of the stack. The first time through prints 1.
ao         Print a linefeed. (ASCII value 10)
:9=      If the top of the stack is 9 (i.e. we just printed 10), push 1.
Otherwise, push 0.
?;    If the top of the stack is non-0, end the program.

Wrap to the start and Repeat. At the end of the loop, we end up
with one more value on the stack than we started with.
• Whoops, I didn't see the other ><> answer that also uses the length of the stack as an incrementer. I'm going to leave this up, but you should really go upvote them if you're going to upvote me. It's even the same byte count. – MildlyMilquetoast Jun 19 '17 at 18:03

# 8th, 18 bytes

( . cr ) 1 10 loop

## TLDCode, 12 10 Bytes

='1'p9{c+}

Clears the stack of the default input, pushes 1 to the stack, parses it from a string to a number, reapeats c+ 9 times, which copies the top of the stack and pushes to the stop of the stack, then incremetnts it. Implicitly prints the stack with _ as the seperator.

Output

1_2_3_4_5_6_7_8_9_10

Previous attempt (12 bytes)

'1'pe9{n+e}=

Pushes 1 to the stack, parses it from a string to a number and prints, then repeats n+e 9 times, which prints a new line, increments the top of the stack and then prints the top. Then it clears the stack to avoid the implicit printing of the default input.

Output

1
2
3
4
5
6
7
8
9
10

# AWK, 26 bytes

BEGIN{for(;i<=9;)print++i}

Try it online!

I don't see an AWK answer, so here we go. I chose to use <=9 rather than <10 just to add a little variety since they have the same byte-count. :)

• Initially I had i++ in the for-loop, but that required a space in the print command. – Robert Benson Jun 22 '17 at 17:39
• A while loop would be the same length here. – CalculatorFeline Jun 22 '17 at 20:03
• True, @CalculatorFeline, but since a while loop is never fewer bytes than a for loop, I've gotten out of the habit of using them. – Robert Benson Jun 22 '17 at 20:19
• I think you can change BEGIN to END to save 2 bytes. – dingledooper Oct 1 '19 at 23:34
• If you use END, then AWK will expect to receive input. The try online would work, but if you typed it in, it would wait until input was supplied. You could just do a <ctrl-d> in bash, but it still expects something as input when you have an END statement. – Robert Benson Nov 18 '19 at 15:57

Firebird, 113 bytes

The compacted select, used to calculate the score is below:

WITH RECURSIVE T AS (SELECT 1 AS I FROM RDB$DATABASE UNION ALL SELECT 1+I FROM T WHERE I < 10 ) SELECT * FROM T The formated select: WITH RECURSIVE T AS ( SELECT 1 AS I FROM RDB$DATABASE
UNION ALL
SELECT 1+I
FROM T
WHERE I < 10
)
SELECT *
FROM T

Short explanation: I start with a select on a system table from firebird, witch always has only one record. Then, using recursion on that projection, I add the column "I" until it reaches 10.

• Welcome to PPCG! Seems like a decent first post, but I think that you could improve it by giving a short explanation for how it works. – Taylor Scott Jun 22 '17 at 19:56
• Thanks. Yes, I should have add a short explanation on my answer. Already updated it. – Filipe Santos Jun 22 '17 at 20:00
• Can you remove some of the spaces/newlines? – CalculatorFeline Jun 22 '17 at 20:02
• @CalculatorFeline Yes I Can! Will do that now, thanks! – Filipe Santos Jun 22 '17 at 20:04

# Python 2.7, 17 bytes

print range(1,11)

Why 11? The range() function is non-inclusive for the end argument.

repl.it

• Duplicate of TuukkaX's Python2 answer posted 11 months earlier. (With sufficient privileges you could see that there are already 3 completely or partially identical deleted answers too.) – manatwork Jun 23 '17 at 7:51
• @manatwork Oops. Sorry. – juniorRubyist Jun 23 '17 at 16:16

# Swift 3, 20 bytes

print(Array(1...10))
• Welcome on Programming Puzzle & Code Golf. About the downvote on your answer: it was automatically applied by the system when @Toto edited your answer from the "First Post" review queue; but no one actually downvoted it. Happy golfing! – Dada Jun 23 '17 at 8:44

# MY (noncompeting), 3 bytes

Here's the hex:

0A 49 27

Finally, a reasonable solution. Explanation:

0A - Push 10 to the stack
49 - Pop n; Push [1 ... n]
27 - Pop n; Output n

# Python 3, 24 bytes

print(list(range(1,11)))

Try it online!

# Carrot, 20 bytes

1 2 3 4 5 6 7 8 9 10

Or if we don't need a separator for 11 bytes:

12345678910

Anything before a ^ in Carrot is placed onto the stack and then that is implicitly output at the end of the program.

With the current version of Carrot this seems to be the shortest way of doing it although I would like to post a none hard coded version if I find one.

# Python 2, 19 Bytes

print range(11)[1:]

Try it online!