# 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!

var QUESTION_ID=86075,OVERRIDE_USER=42570;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<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="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><div id="language-list"> <h2>Winners 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><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>

• 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

# Sesos (binary), 5 bytes

Hexdump:

0000000: 2c4bbc 3301                                       ,K.3.


Try it online!

### How it works

The binary file above has been generated by assembling the following SASM code.

Sesos is a language "based on brainfuck", but is "concise, can be typed easily, has somewhat flexible I/O, and is safe for work".

set numout    ;sets the output to printing a number per line,
add 10        ;now the tape is [10,0,...]
jmp           ;start of loop
fwd 1          ;forward the data head
put            ;output (as number)
rwd 1          ;rewind the data head by 1 cellby 1 cell
sub 1          ;subtract 1 from the cell under data head
;the tape goes from [0,10] to [1,9], to [2,8]
;to ... [8,2] to [9,1] to [10,0] and then halts.
;(implicit jnz) end of loop, goto "jmp" if not zero


In brainfuck: ++++++++++[>+.<-] (assuming decimal output).

# PostScript, 12 bytes

1 1 10{=}for


Output:

1
2
3
4
5
6
7
8
9
10


(Most PostScript interpreters don't actually have a proper stdout, or even a command line, but GhostScript has both and can be used to run this program.)

## Python2 - 19 17 bytes

print range(1,11)


Saved 1 byte, thanks to KevinLau - not Kenny!

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

• Use range instead of xrange, assuming Python 2. In fact, this current version doesn't seem to work on my machine in either Python version. – Value Ink Jul 21 '16 at 9:18
• @KevinLau-notKenny I could've sworn that I tried that, and got nothing to STDOUT. Thanks! – Yytsi Jul 21 '16 at 9:20
• Important: It's only Python 2 – univalence Jul 23 '16 at 18:47
• @ABcDexter I checked it out, very nice! The reason I didn't use Python3, was because I was forced to cast the range object that returns an iterator, to a list. – Yytsi Jul 23 '16 at 19:39
• @TuukkaX Yes, exactly. I'll try some other languages too. Thanks :). – ABcDexter Jul 23 '16 at 19:44

# ><> (Fish) 10 bytes

1l:naoa=?;


This is my first submission and I know their is already a Fish answer but I don't have the reputation to comment.

The main difference is using the l to place the length of the stack onto the stack allowing us to bypass 'adding one' saving a byte.

Using l also means we don't need to preserve the stack value (just the length) so we do not need to duplicate the top of the stack to preserve our values, saving another 2 bytes (one for the duplication of the stack value and another as we do not need to skip any instructions for preserving the stack).

# Groovy, 11 characters

print 1..10


Sample run:

bash-4.3$groovy -e 'print 1..10' [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  # Julia, 12 bytes show([1:10])  In Julia, x:y is a range, inclusive. To cast to a list you need to put brackets around it. Otherwise it will just print the literal characters 1:10. 1 byte saved due to @Dennis. Turns out show works the same as print in this case. • show([1:10]) is 12 bytes, not 13. That needs to be fixed in the header. – user48538 Jul 21 '16 at 13:32 # Atari Basic, 29 Bytes 1 for i=1 to 10 2 ? i 3 next i  • 1 for i=1 to 10:? i:next is probably more concise? I'm certain that Atari BASIC allows multi-statemented lines – Shaun Bebbers Mar 9 '18 at 10:30 • Also if Atari BASIC is similar to Commodore (Microsoft) BASIC, you won't need to say next i - simply next – Shaun Bebbers Mar 9 '18 at 10:31 # BrainFuck, 55 Bytes +++++++++>-->-[-----<+>]+++++++++[-<.+<.>>]<<[->-<]>.-.  Output: 1 2 3 4 5 6 7 8 9 10  (Indents as seperators) Try it here: https://fatiherikli.github.io/brainfuck-visualizer/#KysrKysrKysrPi0tPi1bLS0tLS08Kz5dKysrKysrKysrWy08Lis8Lj4+XTw8Wy0+LTxdPi4tLg== ## Plain TeX (58 bytes) \newcount\c\loop\advance\c1 \the\c\ \ifnum\c<10\repeat\bye  # 𝔼𝕊𝕄𝕚𝕟, 7 bytes ⩤ 1,Ⅹ  Prints out 1,2,3,4,5,6,7,8,9,10  Implicit print, Ⅹ is 10 and ⩤ is range(a, b) so the overall pseudocode is stdout.write(range(1, 10)) Note that, while it is only 5 characters, it still takes up 7 bytes, this is due to the Ⅹ and the ⩤ not being ASCII characters. (Ⅹ is the Roman numeral version) • O my god, another ESMin golfer! Yay! Also, ⩤⁽1Ḋ is 4 chars/7 bytes (Ḋ is the variable for 10, and ⁽ groups numbers/variables into arguments). – Mama Fun Roll Aug 2 '16 at 15:05 • @MamaFunRoll Yeah, ESMin is awesome! Thanks for the tip. – emiflake Aug 2 '16 at 15:07 ## Hexagony, 31 bytes <8!~\\\..)\M\~={{'$;$@.......9$


Try it Online!

Still feeling that there are too many no-ops. Had a 34 bytes first draft:

<{."@;.)!.8.{{..M.\\.\'.$(...0=..1  ### Expanded 31 bytes solution  < 8 ! ~ \ \ \ . . ) \ M \ ~ = { { '$ ; $@ . . . . . . . 9$ . .
. . . .


As in the first draft, uses a < to deflect the IP to NW direction.

This trick is found to be quite useful (for me) when the ending path is short enough after a loop.

Instead of using 10, I used 9 and negate it so the loop is still running 10 times (-9 -8 ... 0 all to the "Left" branch).

Although I managed to increase the number of no-ops in the main loop (NW), I can't modify the main loop due to positioning concerns... Maybe easier to golf off more bytes without using the negation trick.

## Morse code, 65 bytes

.---- ..--- ...-- ....- ..... -.... --... ---.. ----. .----- ----


Copy and paste here to try it out (and listen to the code): http://morsecode.scphillips.com/translator.html

# Vim, 9 keystrokes

I saw that there was already a vim answer, but it's not the shortest, so I thought I'd post the shortest one for completeness sake.

10O0<esc>v{g<C-a>


This only works in vim 8, or later versions of vim 7.4.

Explanation:

10                  " Ten times:
O                 " Open a newline
0<esc>           " And insert a 0
v{         " Visually select everything
g<C-a>   " And create an increasing sequence

• huh. Didn't know about the g<C-a> trick. GG. – Zwei Nov 17 '16 at 2:23

# JavaScript, 14 bytes

_=>12345678910


In the question, it doesn't say anywhere that you must use a delimiter. In fact, it says that I can use any output format that I want, so this answer is valid.

# x86 assembly (32-bit, Linux), 40 bytes

Prints out the numbers from 1 to 10, separated by newlines. The last number is not followed by a newline.

0: 31 db 43 89 d8 b4 0a 50 89 da 42 89 e1 c6 01 30
1: 00 01 50 8d 04 12 cd 80 58 40 3f 73 ee 66 c7 01
2: 31 30 30 e4 cd 80 48 cd 80


Ungolfed:

00000000 <_start>:
0:   31 db                   xor    %ebx,%ebx
2:   43                      inc    %ebx
3:   89 d8                   mov    %ebx,%eax
5:   b4 0a                   mov    $0xa,%ah 7: 50 push %eax 8: 89 da mov %ebx,%edx a: 42 inc %edx 0000000b <loop>: b: 89 e1 mov %esp,%ecx d: c6 01 30 movb$0x30,(%ecx)
12:   50                      push   %eax
13:   8d 04 12                lea    (%edx,%edx,1),%eax
16:   cd 80                   int    $0x80 18: 58 pop %eax 19: 40 inc %eax 1a: 3f aas 1b: 73 ee jae b <loop> 0000001d <end>: 1d: 66 c7 01 31 30 movw$0x3031,(%ecx)
22:   30 e4                   xor    %ah,%ah
24:   cd 80                   int    $0x80 26: 48 dec %eax 27: cd 80 int$0x80


The most notable part of the optimization is the aas instruction, which checks if %al is 10 or above, and, if it is, sets the carry flag, and decrements %al by 6. It is meant to be used to adjust for subtraction—you might find the corresponding aaa, which adds 6 instead, used in a real program here. I have instead made use of it because subtracting 6 gets me 4, which is exactly the number I need for another write syscall—saving me another lea instruction.

# Sinclair ZX80 (4/8K ROM) or Sinclair ZX81/ZX Spectrum (27 tokenized BASIC bytes for the ZX80, 38 tokenized BASIC bytes for the ZX81)

 1 FOR I=1 TO 10
2 PRINT I
3 NEXT I


Or (direct mode, probably works on all 8-bit variants of BASIC):

 PRINT 1,2,3,4,5,6,7,8,9,10


## Sinclair ZX Spectrum (and other BASIC variants except the ZX80/ZX81):

 1 FOR I=1 TO 10:PRINT I:NEXT I


Simple, no?

# Whitespace,

71 bytes, thanks to LeakyNun,

# 63 bytes, thanks to Kevin

Spaces substituted with S, tabs with T, linefeeds with L:

SSSTL LSSTL SLS TLST SSSTSTSL TLS SSSSTL TSSS SLS SSSTSTTL TSST LTSSL LSLTL


Run it!

Output:

1
2
3
4
5
6
7
8
9
10

• @LeakyNun Ok, i'll update the code. I used Notepad++ for the bytecount. – ABcDexter Jul 24 '16 at 8:42
• You can save a lot of bytes by changing the two labels to just one byte. – Leaky Nun Jul 24 '16 at 9:35
• i.e. here: SSSTL LSSTL SLS TLST SSSTSTSL TLS SSSSTL TSSS SLS SSSTSTTL TSST LTSSL LSLTL LSSSL LLL – Leaky Nun Jul 24 '16 at 9:37
• that would be 71 bytes – Leaky Nun Jul 24 '16 at 9:40
• You can remove the exit and second label: SSSTL LSSTL SLS TLST SSSTSTSL TLS SSSSTL TSSS SLS SSSTSTTL TSST LTSSL LSLTL. It will exit with an error after it has outputted all 10 integers, but that's allowed according to the meta. Try it online (63 bytes). – Kevin Cruijssen Mar 13 '18 at 20:28

# Whitespace, 61 59 bytes

[S S S T    N
_Push_1][N
S S N
_Create_Label_0][S N
S _Duplicate][T N
S T _Print_integer][S S S T N
_Push_1][T  S S S _Add][S N
S _Duplicate][S S S T   S T S N
_Push_10][S N
S _Duplicate][T N
S S _Print_char][S N
T   _Swap][T    S S T   _Subtract][N
T   T   S N
_Jump_to_Label_1_if_negative][N
S N
N
_Jump_to_Label_0]


Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online.

Explanation:

Command    Explanation                 Stack          STDOUT    STDERR

SSSTN      Push 1                      [1]
NSSN       Create Label_LOOP           [1]
SNS        Duplicate (1)              [1,1]
TNST       Print as integer           [1]            1
SSSTN      Push 1                     [1,1]
SNS        Duplicate (2)              [2,2]
SSSTSTSN   Push 10                    [2,2,10]
SNS        Duplicate (10)             [2,2,10,10]
TNSS       Print as character         [2,2,10]       \n
SNT        Swap top two               [2,10,2]
TSST       Subtract (10-2)            [2,8]

SNS        Duplicate (2)              [2,2]
TNST       Print as integer           [2]             2
SSSTN      Push 1                     [2,1]
SNS        Duplicate (3)              [3,3]
SSSTSTSN   Push 10                    [3,3,10]
SNS        Duplicate (10)             [3,3,10,10]
TNSS       Print as character         [3,3,10]        \n
SNT        Swap top two               [3,10,3]
TSST       Subtract (10-3)            [3,7]

...

SNS        Duplicate (9)              [9,9]
TNST       Print as integer           [9]             9
SSSTN      Push 1                     [9,1]
SNS        Duplicate (10)             [10,10]
SSSTSTSN   Push 10                    [10,10,10]
SNS        Duplicate (10)             [10,10,10,10]
TNSS       Print as character         [10,10,10]      \n
SNT        Swap top two               [10,10,10]
TSST       Subtract (10-10)           [10,0]

SNS        Duplicate (10)             [10,10]
TNST       Print as integer           [10]            10
SSSTN      Push 1                     [10,1]
SNS        Duplicate (11)             [11,11]
SSSTSTSN   Push 10                    [11,11,10]
SNS        Duplicate (10)             [11,11,10,10]
TNSS       Print as character         [11,11,10]      \n
SNT        Swap top two               [11,10,11]
TSST       Subtract (10-11)           [11,-1]


# Brian & Chuck, 17 bytes

1	1{?
!{.+>-?>.-.


Try it online!

code:

Brian:
1   1   ("1", 9, "1") constants
{?      restart Chuck's code

Chuck:
{       Move Brian to the leftmost character
.+      Print and increment character
>-      decrement counter
?       if counter is greater than zero, switch to Brian (restart Chuck's code)
>.-.    print 10


## Lua, 25 Bytes

for i=1,10 do print(i)end


# Brachylog, 6 5 bytes

Saved one byte thanks to @mat

10yb.


Try it online!

### Explanation

10y        Get the list [0:1:2:3:4:5:6:7:8:9:10]
b.      Output is that list minus the first element

• 5 bytes: 10yb. – mat Jul 21 '16 at 11:57
• @mat Thanks, I didn't thought of that, even though it's even simpler! – Fatalize Jul 21 '16 at 12:00

## Perl 5.10, 14 13 bytes

Almost the same as Perl 6:

say for 1..10


I could've done something like say"@{[1..10]}" which is the exact same thing as in Perl 6, but it is too long. :p

Each number is outputted on a separate line.

Thanks to manatwork for saving 1 byte!

Try it here!

• No need for parenthesis around statement modifier's condition. – manatwork Jul 21 '16 at 14:10
• @manatwork Indeed, thanks! – Paul Picard Jul 21 '16 at 14:11
• OP says separators are ok but not required. I'd just use say 1..10` – Alex Howansky Jul 21 '16 at 17:47