# 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

## 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 at 23:34

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!

# anyfix, 3 bytes

⁴RK


Note that TIO says that this is 5 bytes but that is because of the unicode character ⁴; in the codepage of anyfix (which is the same as the Jelly codepage), this solution encodes to 3 bytes.

## Explanation

⁴   10
R  Range [1..10]
K Join on spaces


Alternatively, ⁴RY separates by newlines. R⁴K and R⁴Y also work because one of the key features of anyfix is that it works with prefix, infix, and postfix (though K and Y will work regardless of what's on the stack because if the top of the stack is not a list or does not exist, then it will use the entire stack as a list). Alternatively, R⁴ or ⁴R and the @l interpreter flag will make it output [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]] because @l makes it output the stack as its string representation in Python.

Try it online!

# AnyDice, 10 bytes

output d10


Try it here.

This program creates and outputs a single 10 sided die. This lists out the numbers on the die (1-10) next to a bar graph of the probabilities in the standard output form.

# Eukleides, 26 bytes

for i=1 to 10
print i
end


Beats hardcoding by 2 bytes.

## T-SQL, 27 bytes

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


Less boring with a WHILE, 51 bytes

DECLARE @ INT=1WHILE @<11BEGIN PRINT @ SET @+=1 END


# ><>, 17 Bytes

1>:nao1\
;\?(b:+/


Pretty basic:

1                       | Push 1 to the stack
>                      | Make sure pointer is going the right direction
:n                    | Duplicate the number and print it
ao                  | Print a new line
1\                | Increment, redirect pointer
+/                |-┘
(b:                  | Check that the result is less than 11
;\?                     | If it is, continue looping, else end.


# Implicit, 10 bytes

(;.@%<10)&


Try it online!

(            do..while loop
;            pop (nothing initially, n<10 after that)
.           increment (0 initially, n after that)
@          output ASCII value of n for delimiter
%         output n as integer
<10      push n<10
)    loop while top of stack truthy (n<10)
&   exit (no implicit output)


Output (? denotes an unprintable):

?1?2?3?4?5?6?7?8    9
10


# Bitwise, 208191 175 bytes

-17 bytes using the registers 3 and 4 instead of function frame registers
-16 bytes using position-based jumps instead of LABELs

.A:
AND $1$2 3
XOR $1$2 $1 SL 3 &1$2
JMP &-4 $2 RET$1
.G:
NOT $1 3 A$2 3 4
A 4 &1 4
SR 4 &31 4
AND 4 &1 4
RET 4
.L:
G $2$1 3
RET 3
A 1 &1 1
OUTI 1 &1
L 1 &10 2
JMP &-4 2


Try it online!

Explanation:

.A:          # subroutine: arg3 = arg1 + arg2
.G:          # subroutine: arg3 = arg1 > arg2
.L:          # subroutine: arg3 = arg1 < arg2
A 1 &1 1     # add l1 (literal 1) to r1 (register 1)
OUTI 1 &1 -1 # output r1 as integer
L 1 &10 2    # set r2 to r1 < 10
JMP &-4 2    # jump 3 lines back in the code if r2 is nonzero


Output:

1 2 3 4 5 6 7 8 9 10


# Cubically, 16 bytes

(*1+1/1%@LUL'B)8


Try it online!

(*1+1/1%@LUL'B)8
(                 do..while loop
@          output notepad as ASCII (delimiters)
LUL'B     algorithm with period 10
)8  loop while cube unsolved


Output (? denotes an unprintable):

1?2?3?4?5?6?7?8?9   10


# FALSE, 18 17 bytes

0[1+$11-][$."
"]#


Explanation:

0 {push 0}
{conditional function}
[
$11- {check if 11} ] {loop function} [$. {print number}
"
" {print line break}
]
# {while loop (run second function while first returns true)}


# Excel VBA, 20 Bytes

Anonymous VBE immediates window function that takes no input and outputs to the VBE Immediates window

For i=1To 10:?i:Next


# uBASIC, 20 bytes

Anonymous function that takes no input and outputs to the console

0Forx=1To10:?x:NextX


Try it online!

# Python3 - 19 Characters

print(*range(1,11))


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

# Rust, 42 bytes

fn main(){for i in 1..11{print!("{},",i)}}


# jamal, 17 characters

{@for i/1..10/i }


Sample run:

bash-4.4\$ jamal.pl number.jam
1 2 3 4 5 6 7 8 9 10


# Pyt, 3 bytes

1ᴇř

1     push 1
ᴇ    10^1
ř   range from 1 to 10
Implicit output


Try it online!

# Javascript (potentially non-competing)

As a function (6 bytes):

_=>110


Full program (10 bytes):

alert110


This prints all number from 1 to 10 inclusive in binary...
If you closely read the question, there is never any mention about mandatory separators (thus allowing 123456...) nor the output's base...

# Jotlin, 15 12 bytes

p((0..9)+10)


Gets the numbers 0..10, makes a list out of them, and then prints the result

# (non-competing) rig, 3 bytes

rig is a work-in-progress esoteric stack-based language. I'm just having fun with looking for challenges it can already solve, with its few commands.

τr+


is a valid code that prints "1,2,3,4,5,6,7,8,9,10"

Try it here

Why?

τ    - push 10 to the stack              [10]
r   - push range(10) to the stack       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+  - increment every element           [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- implicit print


# KoopaScript, 78 (28, 20) bytes

def i a if \%va is \%v set a 0;setath a \%va + 1;if \%va smaller 11 print \%va


This prints the numbers 1 to 10, as well as a lot of information about the currently running code (because reasons). KS doesn't actually have a way to break loops yet, so this keeps running until the interpreter is reloaded. It stops printing at 10, though.

def i a               - Define a function with the name i and call it 1000/NaN (i.e. many) times a second
if \%va is \%v        - if the variable with the name a is undefined,
set a 0;              - set it to 0
setath a \%va + 1;    - set the variable a to <the variable with the name a> + 1
if \%va smaller 11    - if the variable with the name a is smaller than 11,
print \%va            - trace the variable with the name a


To avoid printing debug info, either load this in an init script, or use this slightly longer (90) version that disables logging:

def i a set verbose;if \%va is \%v set a 0;setath a \%va + 1;if \%va smaller 11 print \%va

set verbose;          - set the variable called 'verbose' (which handles whether to trace debugging stuff) to ""


Alternatively,

print "1 2 3 4 5 6 7 8 9 10"


This is only 28 bytes and technically does what the specification entails. Other commands, e.g. if, display all the numbers, but, as it's caused by an error in the program, it doesn't display if logging is disabled.

Technically,

1 2 3 4 5 6 7 8 9 10


prints all the numbers with commas between them, in the debug log. That brings it down to 20. I guess it's up to the reader (stacker? golfer?) to decide which one is the most correct

# Commodore BASIC, method 1 (28 bytes)

0?1,2,3,4,5,6,7,8,9,10


### Method 2 (27 26 bytes)

0FORI=1TO10:?I:NEXT


### Method 3 (40 bytes)

0I=1
1?I,:I=I+1:IFI<11THEN1


### Method 4 (32 bytes)

0?I,:I=I+1:IFI<11THEN0
I=1:GOTO0


### Method 5 (20 bytes)

0?"12345678910


### Method 6 (25 bytes) CBM BASIC V2 only [C64/C64Mini or VIC-20]

0I=I+1:?I:ON-(I<10)GOTO


I'm working out the memory used with ? 38911-(fre(0)-65536*(fre(0)<0)) on a Commodore 64.

# Seed, 42324039 3981 bytes

To be golfed.

11 806065440241409087125357198607542800075970572928765093042958164984128856153119364694304946533565974155065813564463607464907294493213625991570210498180131922642836049048379926678214090306958078942950505666942158861663318082805922649360548872276728753092705551896201785489318797454097467866454815778688721780170362909784978852186756623253868868917034035335528463229661772327867673360158173714723733025733656646487909489808220640703644162017799947346882823939914644265408484708544566367174322747059393061445510836708923637982737011363312927325448282786060215442674975310709523697911998742881715764878830975686475127091070151990734113230052589483007904386955837951416230150553553131824081272209795780490205576443141598594094128682959852257277648831764416301409205933849585487706444517684177487650836580944108733813423567329150282262574305747736976499413900964122878760201959007114022481011295839141271138446203186069264532462250500186116493184286012088625239590991537830133224608224949348931933311034455280978164515936125672561757104517575527099692465553902153481143524868360127998596923638301974413167583429193105287970847431486813381197765539764522094782334194830005111603128673518265195317929281022739571069159575305773074583173243911197334517405412628068284686691469982559791730541223895403558031955848768117060646768348463561209935808045637507281128179915889035768211511504144114447348017724691523076211025635445333081644368060430405389019848215116047520242946447978917490619742817523907421559319563570816232286092378925478777387843124296450405990835394943021252863488969545687903232603331252281246680860082655523490245738107512918342578050153655018310720283275985429190062871812385817909146120892975424714212971890662091259299688100739835789852338707333214399083184648552682989269071097042033924364887158088125417342061047907455595001558776113845342454604060641417114322284932278126981432767955018317987960683429833483125151020913178712494155310545261553444170641615117711305756617133820567957209040625095889033833683868477968222981257864647555382502179925116320599028456728151421211950504164587366555426478479957000176097833838329163859553682184378396176530388849222864560228925976975341162944244301834305126128097819354250219559409487388887032429560483598135806164050794728591878728116747953265919795701481292222092677282626562421120330436952746759320383166496345689472683465785160396471114988424810146619802843389460581036625456336614635949441077117888570209114560201469774858952308539634363125726651042307946127813908314293240378846347559662225224004298822713302904050471977675138246925540751643515879128105969891674920959645532198204680833150120401421252646736795292132103275342152265451058336500878555688383134027160586652276624279294501247326175308886148638933724425782375226226354458022684652099014849380343822015940473137950787091045988775407006084669595433268270085699081145780497235745383972369977375564713816849012360495596752065665250235877504147680897910657602532177993907221958136528121236676455264099257048759319470710174615005668917675853889646496531814039709503285164186416096735666867062585670181891889551756178657495723233678891549411496581200696462439988553007997103954989290028776888309286564702133992674291744804531900851060090385178725409757099606879757766288322010567612896350258272282241111517435795569303408578713936760574865986977532034796036053889911992836923158428809242575557886427002935479153509101800373188079516076598125218940752155364580400861924119667725548877677649837117601878482958020472764206345843076482381692875591020886968748894499648171413242376922343979630964910668516043571246988639289969853916731069660002514237788846617524295024699798200028558752532671916185460167291108476912591550362203490594401624213451585637461718363114331483866061411154610681167668195013207060532734483192219734129165226320299742868143084807270641847983148272764305800992489421803505337228286598600236556437401089147741524552516814465259338644189950504662


Try it online!