# 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

# TacO, 7 bytes

@%10
i


try it online! The number 10 is the first branch of the looping construct %, so TacO runs the second branch, which just contains i, 10 times, giving i numbers 1-10.

# Seed, 42324039 3981 bytes

To be golfed.

11 806065440241409087125357198607542800075970572928765093042958164984128856153119364694304946533565974155065813564463607464907294493213625991570210498180131922642836049048379926678214090306958078942950505666942158861663318082805922649360548872276728753092705551896201785489318797454097467866454815778688721780170362909784978852186756623253868868917034035335528463229661772327867673360158173714723733025733656646487909489808220640703644162017799947346882823939914644265408484708544566367174322747059393061445510836708923637982737011363312927325448282786060215442674975310709523697911998742881715764878830975686475127091070151990734113230052589483007904386955837951416230150553553131824081272209795780490205576443141598594094128682959852257277648831764416301409205933849585487706444517684177487650836580944108733813423567329150282262574305747736976499413900964122878760201959007114022481011295839141271138446203186069264532462250500186116493184286012088625239590991537830133224608224949348931933311034455280978164515936125672561757104517575527099692465553902153481143524868360127998596923638301974413167583429193105287970847431486813381197765539764522094782334194830005111603128673518265195317929281022739571069159575305773074583173243911197334517405412628068284686691469982559791730541223895403558031955848768117060646768348463561209935808045637507281128179915889035768211511504144114447348017724691523076211025635445333081644368060430405389019848215116047520242946447978917490619742817523907421559319563570816232286092378925478777387843124296450405990835394943021252863488969545687903232603331252281246680860082655523490245738107512918342578050153655018310720283275985429190062871812385817909146120892975424714212971890662091259299688100739835789852338707333214399083184648552682989269071097042033924364887158088125417342061047907455595001558776113845342454604060641417114322284932278126981432767955018317987960683429833483125151020913178712494155310545261553444170641615117711305756617133820567957209040625095889033833683868477968222981257864647555382502179925116320599028456728151421211950504164587366555426478479957000176097833838329163859553682184378396176530388849222864560228925976975341162944244301834305126128097819354250219559409487388887032429560483598135806164050794728591878728116747953265919795701481292222092677282626562421120330436952746759320383166496345689472683465785160396471114988424810146619802843389460581036625456336614635949441077117888570209114560201469774858952308539634363125726651042307946127813908314293240378846347559662225224004298822713302904050471977675138246925540751643515879128105969891674920959645532198204680833150120401421252646736795292132103275342152265451058336500878555688383134027160586652276624279294501247326175308886148638933724425782375226226354458022684652099014849380343822015940473137950787091045988775407006084669595433268270085699081145780497235745383972369977375564713816849012360495596752065665250235877504147680897910657602532177993907221958136528121236676455264099257048759319470710174615005668917675853889646496531814039709503285164186416096735666867062585670181891889551756178657495723233678891549411496581200696462439988553007997103954989290028776888309286564702133992674291744804531900851060090385178725409757099606879757766288322010567612896350258272282241111517435795569303408578713936760574865986977532034796036053889911992836923158428809242575557886427002935479153509101800373188079516076598125218940752155364580400861924119667725548877677649837117601878482958020472764206345843076482381692875591020886968748894499648171413242376922343979630964910668516043571246988639289969853916731069660002514237788846617524295024699798200028558752532671916185460167291108476912591550362203490594401624213451585637461718363114331483866061411154610681167668195013207060532734483192219734129165226320299742868143084807270641847983148272764305800992489421803505337228286598600236556437401089147741524552516814465259338644189950504662


Try it online!

Javascript 45 Bytes

alert("10charstrn".split("").map((e,i)=>i+1))


This is currently quite poor, but if there happens to be a JS constant which is an array of length 10, this could improve a lot.

• Array(10).fill() is the first thing that came to mind for an array of length 10. (Array(10).map... does not work, at least on my browser.) – Value Ink Sep 16 '19 at 23:52
• I mean, just alert([1,2,3,4,5,6,7,8,9,10]) is way shorter – Jo King Sep 17 '19 at 0:39
• I'm pretty sure alert([1,2,3,4,5,6,7,8,9,10]) is already an answer somewhere within these seven pages of answers... might as well golf the method that's already here methinks – Value Ink Sep 17 '19 at 4:37
• (top+'').split('',10) <-- saves 1 byte compared to "10charstrn".split(""). top refers to window.top, and the string representation is "[object Window]" (15 chars). The .split() method takes a separator and an optional limit. Since all you need is 10 chars, split into an array, this should do just fine. – Ismael Miguel Nov 18 '19 at 11:43

## ROOP, 15 bytes

123456789
h(10)


Solution with hardcoded numbers, I'm still trying to find a shorter program.

In this language each digit becomes an individual object. Number 10 is written in parenthesis to make it a single object. The operator h prints all objects that are currently in the program, separated by a space, then halt.

• seems that 7 is missing – roblogic Sep 15 '19 at 3:57
• @roblogic wow, you are right, fixed. – DarkPhantom Sep 16 '19 at 15:48

## Keg, 5 bytes

I am too lazy to change my answers to conform the new code page, unless I get notified.

ėÏ_(.


Push 10(saving a byte), take iota [10..0], remove last, and then print.

# Clojure REPL, 12 bytes

(range 1 11)


I think this is self explanatory code

• Hello and welcome to PPCG. The challenge asks for a program to output to stdout, meaning you either need to add println or potentially declare your language as "Clojure REPL" per standard rules. – Jonathan Frech Sep 17 '19 at 7:25
• Oh I see, thank you – Ampersanda Sep 18 '19 at 1:30

# 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

# Poetic, 163 bytes

this is asking a lot
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


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


Or with the additional NULs.

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

# Intcode, 44 42 bytes

-2 bytes thanks to rootbeersoup

204,8,9,8,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 six bytes?

• Saves 2 chars: 204,8,9,8,1205,8,0,99,1,2,3,4,5,6,7,8,9,10 – rootbeersoup Jan 30 at 5:33

## W, 2 bytes

Tk


Constant 10, then range from 1 to that. Added for completeness.

# 1+, 25 22 bytes

1:1(|1+":1+":1+":)()()


...

EDIT: The boring solution is shorter.

# dotcomma, 67 bytes

[[[[[[[[[[.,][.].,][.].,][.].,][.].,][.].,][.].,][.].,][.].,][.].,]

The shortest is the direct approach: Put a 1 on queue and then, nine times put the previous value plus 1 on the queue. Output implicitly.

<script src="https://combinatronics.com/RedwolfPrograms/dotcomma/master/interpreter.js"></script><script src="https://code.jquery.com/jquery-3.5.1.min.js"></script><script>$(document).ready(function () {$("#btnInterpret").click(function () {$("#txtResult").text(interpret($("#txtCode").val(), $("#txtInput").val(),$("#lstOutputAs").children("option:selected").val()));});});</script><style>.textBox {background-color: white;border: 1px solid black;font-family: Courier New, Courier, monospace;width: 100%;}</style>Code: <textarea id="txtCode" type="text" class="textBox" style="height: 200px">[[[[[[[[[[.,][.].,][.].,][.].,][.].,][.].,][.].,][.].,][.].,][.].,]</textarea><br />Input: <textarea id="txtInput" type="text" class="textBox"></textarea><br /><input id="btnInterpret" type="button" value="Run" />Output as: <select id="lstOutputAs"><option value="">Number array</option><option value="true">String</option></select><br />Result:<br /><div id="txtResult" class="textBox" style="overflow-wrap: break-word"></div>

# BitCycle-u, 40 bytes

v0 ~
v1~/
AB~
v000000<
AB\ 000^
v =@
!1<


Try it online!

Explanation pending. I need to sleep first.

(I also found a 36-byte program that outputs 0 through 9, but I haven't found a good way to turn it into 1 through 10.)

# 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.
• 14 – squid Sep 16 '19 at 13:17

# 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