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?) Jul 21, 2016 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. Jul 21, 2016 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.) Jul 21, 2016 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. Jul 21, 2016 at 14:09
• I can't believe every single of the (currently) 71 answers assumes the base should be decimal… Jul 22, 2016 at 15:05

k, 5 bytes

1+!10


Explanation:

1+ //Projection of +, add 1 to the argument
!10 // "til" 10 - i.e. generate a list of numbers from 0 to n-1


Output:

1 2 3 4 5 6 7 8 9 10

• You can also do 1_!11, which seems faster (at least in kdb+).. count 0..10 then drop the first element, rather than adding 1 to each item of a 10 item list.
– mkst
Jun 15, 2017 at 22:34

Java 7, 50 bytes

void m{for(int i=1;i<11;System.out.println(i++));}

• Welcome to Programming Puzzles & Code Golf! Just so you know, the downvote was cast automatically by the Community user when your answer was edited. I consider this a bug. I'd upvote, but I don't know Java and have no idea how to test your code. Could you maybe include a link to an online interpreter? Oct 18, 2016 at 16:38

Lithp, 64 bytes

((import "lists")(def f #::((each (seq 1 10) #N::((print N))))))


Fairly simple, but unfortunately fairly verbose. I'm counting the import because modules don't automatically load (ie, each and seq are from the lists module, and need to be imported manually.)

To use:

(
(import "lists")(def f #::((each (seq 1 10) #N::((print N)))))
(f)
)


Alternate Answer, 68 bytes, recursive and no modules

(def x #::((def y #N::((print N)(if (< N 10) ((y (+ N 1))))))(y 1)))


Defines a recursive function y which calls itself until N is 10.

(
(def x #::(
(def y #N::(
(print N)
(if (< N 10) (
(y (+ N 1))
))
))
(y 1)
))
(x)
)


Sadly my language is a bit verbose, but Lisp-like language tend to do that. I'm more interested in ensuring the language can handle everything I'd want to throw at it.

DARTMOUTH BASIC,42 BYTES

EH, WHY NOT?

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

• Do you need the 4 END with DARTMOUTH BASIC? Does the symbolic listing not end when there is nothing left to interpret? Jun 11, 2019 at 15:48

ASMD, 5 bytes

T(i{p


Body must be at least 30 characters; you entered 20.

APL with any ⎕IO, 9 bytes.

1-⎕IO-⍳10


APL with ⎕IO=0, 5 bytes.

1+⍳10


Japt, 3 bytes

1oB


This is very simple: o creates a semi-inclusive range between two values, and B is pre-defined to 11. Thus, this creates the range [1..11), or [1,2,3,4,5,6,7,8,9,10], which is automatically sent to STDOUT.

Test it online!

• Why not just Aõ? (EDIT: Should have checked the date first!) Feb 20, 2018 at 15:32

MATLAB, 4 Bytes

1:10


Output:

 1     2     3     4     5     6     7     8     9    10


The colon operator acts as a range function in Matlab, working from the preceding number to second one, with a default step of 1. (1:3) returns [1,2,3]

As for printing, MatLab Auto prints any line not terminated with a semicolon; Printing a line actually saves space!

Brainf***, 57 Bytes

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


This is my first attempt at a program in this language. I think it's pretty optomized

• Are you sure? I'm afraid this in best case outputs the characters with codes 1..10 (“␁␂␃␄␅␆␇␈␉␊”), not the numbers 1..10. Nov 16, 2016 at 20:19
• Yeah, so that's my bad. The Esoteric IDE that I'm using has it print out 1,2,3...10 Nov 16, 2016 at 20:22
• Okay, I've redone it. Does that look better? Nov 16, 2016 at 21:29
• Yepp, except the . immediately after the last loop, which outputs an unnecessary ␀ character. Nov 17, 2016 at 11:17
• Ha. Forgot about that. I was using that for troubleshooting. Thanks for the help! Nov 17, 2016 at 15:18

Brainfuck, 59 Bytes

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


Cubix, 12 bytes

\;;u>)ONo-?@


Test it online! I will add an explanation within the next few hours.

Pushy, 3 bytes

TR_


(non-competing as the language postdates the challenge)

It's extremely simple:

T  % Push 10
R  % Generate range (1 to 10, including both endpoints)
_  % Output representation of stack (1 2 3 4 5..)


VIM, using Bash and coreutils: 9 bytes

:!seq 10

• Technically this is 10 bytes because you need to hit <CR> for the command to work. Nov 16, 2016 at 21:31
• @DJMcMayhem Good point. However, it does not need <CR> for the command to work if the command is passed to vim from the shell vim -c ':r!seq 10'. Of course one has to hit <CR> to execute the command from the shell, but this is then 'technically' not part of the vim command. Slightly different, but one could even argue that a C program without a newline wouldn't be valid either link.
– ttq
Dec 6, 2016 at 11:18
• Actually, if you were to take that approach, you wouldn't even need the colon, so it could be 8. I think technically that would be a vimscript answer (or ex?), rather than vim. You could post that as a separate answer I suppose Dec 6, 2016 at 23:00
• It can be even reduced to 7 bytes, if you only care about displaying the numbers 1 to 10. Then the r can be omitted too.
– ttq
Dec 7, 2016 at 12:37

SmileBASIC, 19 bytes

FOR I=1TO 10?I
NEXT


Nothing to see here

Batch: 36 bytes

for /l %%i in (1,1,10) do (echo %%i)


Breakdown:

for: for operation in batch. Similar to C.

/l: option for the above command

%%i: define %%i, or %i in CMD, just like how you would define i in a for loop in C

in (1,1,10): pretty much "in (start, step, increment)", or in C " for (start, increment, step)".

do: well, run the code after this each time %%i is between 1-10.

(echo %%i): print %%i which is going from 1 to 10


Minecraft 26

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


I know there is no special clue in it but I don't know.

scoreboard objective add a dummy


Repeating

give @p wool
stats entity @p set AffectedItems a @p
scoreboard player set @p a 0
clear @p wool 0 0
tellraw @p {"selector":"@p","objective":"a"}

• IIRC you don't need the quotes when using the say command. But this is not relevant, because your answer with the say command is invalid anyway, because hardcoding the output is a standard loophole everywhere other than at [kolmogorov-complexity] challenges. See meta.codegolf.stackexchange.com/a/1063/29672 Jul 23, 2016 at 11:22
• @CocoaBean This IS kolmogorov-complexity Jan 26, 2017 at 18:54

Q/KDB+ 8 Bytes

1+til 10


Explanation:

til 10


Outputs list of numbers 0 to 9

1+


Increments each number in the list by one

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

• 1 byte shorter using k shorthand 1+(!)10
– mkst
Jun 15, 2017 at 22:26

Python 3: 24 bytes

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


Simply print a list of the range.

Outputs:

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

Microscript, 7 bytes

10c1p]h


Microscript II, 10 bytes

0s{1+Ps}s10*


Perl, 19 bytes

@x=1..10;print"@x";


The ".." operator can print an ascending list of numbers or letters.

So @x = A..Z; print "@x"; will print capital letters A through Z.

I saved quite a few bytes by removing all spaces.

J-uby, 4 bytes (non-competing)

10.+


In J-uby, n.+ is the same as [*1..n].

• So, what is J-uby? Is it like Ruby's analog of Pyth, combined with J or something like that? Jun 19, 2017 at 20:41
• @ZacharyT it's not like pyth. J-uby is an extension of ruby that gives it concise fictional programming features in the style of J. I'm now adding other methods as aliases to make it more suitable for code golfing. The most important principle is that any valid Ruby code is valid J-uby code. Jun 19, 2017 at 20:45
• (It's not fictional, it's functional). So it's just somewhat like the Babel ES6 transpiler, in the fact that it converts J-uby code to Ruby? Jun 19, 2017 at 20:47
• @ZacharyT auto correct is annoying. And since Ruby is awesome, you can just require 'juby' and then it is a j-uby program through metaprogramming. Jun 19, 2017 at 20:52
• Yeah, I love how you used Ruby's wacky language features to enhance it. I wonder what someone could do with Perl this way, considering you can define new operators? Jun 19, 2017 at 21:02

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. Jun 22, 2017 at 17:39
• A while loop would be the same length here. Jun 22, 2017 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. Jun 22, 2017 at 20:19
• I think you can change BEGIN to END to save 2 bytes. Oct 1, 2019 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. Nov 18, 2019 at 15:57

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.

Charcoal, 5 bytes

Ｉ…·¹χ


Try it online!

Explanation:

Ｉ        Implicitly print the elements (casted as string) of
…·      the inclusive range
¹χ    from 1 to 10 (default value of the χ variable)

• 4 bytes now Feb 21, 2018 at 1:01

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


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


Pyth, 4 2 bytes

Well, I guess I think more about legitimate functionality/usability, but this is Code Golf, where usability comes after functionality.

-2 by not formatting my output.

ST


Explanation:

S        1-indexed range from 1 - ...
T       Ten


Try It Online!

Pyth, 4 bytes

VSTN


Explanation:

V        For...
ST      in the 1-indexed range from 1 - 10 (T)
N     Print the current item


Try it online!

Or alternatively...

VThN


Explanation:

V        For...
T       In range from 0 - 9
hN     Print (the current item + 1)


Try it online!

Pretty simple.

• Your output format can be whatever your language supports. This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), prefixes and postfixes (like [...]). Dec 29, 2017 at 7:17
• This means that ST is valid Dec 29, 2017 at 7:18
• @Tornado547 wow, that is odd. many thanks Dec 30, 2017 at 3:49

Kotlin: 30?/31/49 bytes

Variable of function type: 30 bytes

val a={(1..10).map(::println)}


This might be considered cheating.

Invokable via a() like the later function. Functions are first-class citizens in Kotlin, so they can be assigned to variables aswell. The type of ´val a´ is technically () -> List<Unit>, a function that takes nothing and returns a "list of nothing", but we wouldn't be on code golf using a language that doesn't have implicit types, would we? 😊

Function: 31 bytes

fun a(){(1..10).map(::println)}

Executable: 49 bytes

fun main(a:Array<String>){(1..10).map(::println)}


Julia 0.6, 11 bytes

show.(1:10)


Try it online!

Pip, 3+1 = 4 bytes

\,t


Runs with the -n flag to separate the output with newlines.

Try it online!

Explanation:

\,         Inclusive range of 1 to
t        10

• @DLosc Thanks, that shortens it considerably. But how does it owrk though? Does \, create a range-object with the values 1 to t==10 inclusive, which it auto-prints (as that range-object is the last variable touched by Pip?) Feb 3, 2018 at 11:54
• Yep! Exactly. (It's possible this is "using features newer than the question," because I can't recall when I changed the behavior so non-infinite ranges would output like lists, but that's allowable anyway. \, is not an issue--it was added last January.) Feb 3, 2018 at 17:48