61
\$\begingroup\$

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!

Leaderboard

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>

\$\endgroup\$
17
  • 10
    \$\begingroup\$ Related (duplicate?) \$\endgroup\$
    – Luis Mendo
    Commented Jul 21, 2016 at 9:07
  • 17
    \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 21, 2016 at 9:54
  • 11
    \$\begingroup\$ @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.) \$\endgroup\$ Commented Jul 21, 2016 at 10:01
  • 20
    \$\begingroup\$ @xnor Quite frankly, I'd rather close the other challenge as a duplicate of this one. The requirement pretty much ruins it. \$\endgroup\$
    – Dennis
    Commented Jul 21, 2016 at 14:09
  • 11
    \$\begingroup\$ I can't believe every single of the (currently) 71 answers assumes the base should be decimal… \$\endgroup\$ Commented Jul 22, 2016 at 15:05

278 Answers 278

1
2 3 4 5
10
77
\$\begingroup\$

C, 36 bytes

main(i){while(printf("%d ",i++)<3);}

This works because the loop terminates after the first 2 digit number.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ There's no mention of being able to pass in parameters to the function. \$\endgroup\$ Commented Jul 21, 2016 at 13:27
  • 11
    \$\begingroup\$ @AshBurlaczenko What are you talking about? This is a standard technique in golfing to initialise an int to 1. You don't need to pass any command line arguments. In fact, doing so will cause the program to produce the wrong output. \$\endgroup\$
    – xsot
    Commented Jul 21, 2016 at 13:39
  • 7
    \$\begingroup\$ @AshBurlaczenko By consensus we have agreed that programs may assume they will not be called with unnecessary input (in this case, no additional command line arguments, beyond the program itself). That means i here will always be 1 when this program is run. Did you mean something else? \$\endgroup\$ Commented Jul 21, 2016 at 13:41
  • 2
    \$\begingroup\$ Sorry, I've not written C but assumed it's default value would be 0 as in every language I've used. \$\endgroup\$ Commented Jul 21, 2016 at 13:50
  • 21
    \$\begingroup\$ @AshBurlaczenko In C, the first argument to main is the number of command line arguments (including the executable name itself). Since no additional arguments are passed, that count is 1. The second argument to main is the actual list of command line arguments, but that argument is ignored in this program. \$\endgroup\$ Commented Jul 21, 2016 at 15:43
63
\$\begingroup\$

HTML, 44 bytes

<ol><li><li><li><li><li><li><li><li><li><li>

This is longer than hardcoding the output, but it is more interesting this way. It creates an ordered list (<ol>) with ten empty list elements (<li>). By default ordered lists are delimited by decimal numbers starting with 1 and a period.

HTML5 is very forgiving regarding unclosed tags, so it closes the li tags implicitly.

\$\endgroup\$
3
  • 9
    \$\begingroup\$ +1 for abusing HTML5's forgivingness (?). \$\endgroup\$
    – hyperneutrino
    Commented Nov 17, 2016 at 15:34
  • 1
    \$\begingroup\$ Cold-blooded. I love it. \$\endgroup\$
    – ricdesi
    Commented Nov 17, 2016 at 19:03
  • 2
    \$\begingroup\$ Actually, NinjaBearMonkey and @HyperNeutrino, this isn’t “forgiveness” per se; HTML5 is pretty explicit about which tags are allowed to be left unclosed. It’s just that lists and list items are two that are. \$\endgroup\$
    – KRyan
    Commented Feb 5, 2018 at 14:34
48
\$\begingroup\$

Bash, 12 characters

echo {1..10}

Sample run:

bash-4.3$ echo {1..10}
1 2 3 4 5 6 7 8 9 10

Bash + coreutils, 10 characters

(Just trying to be funny and using ': No such file or directory↵ls: cannot access ' as separator.)

ls {1..10}

Sample run:

bash-4.3$ ls {1..10}
ls: cannot access '1': No such file or directory
ls: cannot access '2': No such file or directory
ls: cannot access '3': No such file or directory
ls: cannot access '4': No such file or directory
ls: cannot access '5': No such file or directory
ls: cannot access '6': No such file or directory
ls: cannot access '7': No such file or directory
ls: cannot access '8': No such file or directory
ls: cannot access '9': No such file or directory
ls: cannot access '10': No such file or directory

Bash + coreutils, 6 characters

(Just trying to be boring. Or not just trying…)

seq 10

Sample run:

bash-4.3$ seq 10
1
2
3
4
5
6
7
8
9
10
\$\endgroup\$
13
  • 7
    \$\begingroup\$ Last one is just seq/coreutils, bash not involved. \$\endgroup\$
    – hyde
    Commented Jul 21, 2016 at 18:07
  • 1
    \$\begingroup\$ @hyde: Without bash the call to seq wouldn't be possible, would it? \$\endgroup\$
    – univalence
    Commented Sep 6, 2016 at 8:13
  • \$\begingroup\$ In my vision, if we leave out bash, then seq would be the interpreter. But then 10 is a valid program in “seq” language? \$\endgroup\$
    – manatwork
    Commented Sep 6, 2016 at 8:25
  • \$\begingroup\$ Never try this at your console: echo {1..1000000000} If you curious, do with your own risk. \$\endgroup\$
    – Brain90
    Commented Oct 18, 2016 at 14:58
  • \$\begingroup\$ @Brain90, there is no danger on my poor 8Gb RAM machine. ;) “bash: brace expansion: failed to allocate memory for 1000000000 elements”. At least with bash 4.3.46. \$\endgroup\$
    – manatwork
    Commented Oct 18, 2016 at 15:25
31
\$\begingroup\$

Jelly, 2 bytes

⁵R

Explanation

⁵  Return the fifth command line argument or 10
 R Range
   Implicit output
\$\endgroup\$
5
  • 7
    \$\begingroup\$ ⁵R, two bytes \$\endgroup\$
    – Luis Mendo
    Commented Jul 21, 2016 at 9:19
  • 28
    \$\begingroup\$ Why on Earth would someone invent a language in which a command returns either the fifth argument or the integer 10?.. \$\endgroup\$ Commented Nov 14, 2016 at 15:11
  • 18
    \$\begingroup\$ @AndreïKostyrka Because Dennis \$\endgroup\$ Commented Nov 14, 2016 at 15:23
  • 3
    \$\begingroup\$ Is there an encoding where is just one byte? Since it's 3 bytes in UTF-8, the length of the program should be 4 bytes. \$\endgroup\$ Commented Jan 26, 2017 at 14:25
  • 5
    \$\begingroup\$ @RadovanGarabík Jelly uses its own codepage \$\endgroup\$ Commented Jan 26, 2017 at 15:09
22
\$\begingroup\$

05AB1E, 2 bytes

Code:

TL

Explanation:

T   # Constant for 10
 L  # Range

Try it online!.

\$\endgroup\$
1
  • 6
    \$\begingroup\$ When I saw this, I felt the need to say "tl;dr". :P +1, by the way. \$\endgroup\$
    – hyperneutrino
    Commented Nov 17, 2016 at 15:35
22
\$\begingroup\$

Brainfuck, 58 bytes

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

Try it online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Beat me to it, and shorter too, will post mine anyway as I don't think we've used the same trick. Have my +1 :) \$\endgroup\$
    – Katenkyo
    Commented Jul 21, 2016 at 10:00
  • \$\begingroup\$ I was close with 67 bytes, but not close enough: ++++++[>++++++++<-]>>>++++++++++[-<+<<+>>>]<[-<.+<.>>]<<-[>-<-]>.-. \$\endgroup\$ Commented Dec 29, 2016 at 17:36
18
\$\begingroup\$

LOLCODE, 79 bytes

IM IN YR l UPPIN YR v TIL BOTH SAEM v AN 10
VISIBLE SUM OF v AN 1
IM OUTTA YR l

This code may need some tweaking depending on the compiler you're using. Some want you to add HAI/KTHXBYE, some want you to declare the variable ahead of time. One compiler breaks if your loop name is shorter than two characters, even though the loop name is never used.

\$\endgroup\$
15
\$\begingroup\$

CJam, 6 5 bytes

A,:)`

1 byte saved thanks to Luis Mendo

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

Explaination:

A,      e# Push a list from 0 to 9.
  :)    e# Increment all values.
    `   e# Stringify the list.

Try it online!

\$\endgroup\$
1
  • 4
    \$\begingroup\$ i like the smileyface. (Isn't there an error in your explanation: A, creates a list from 0 to 9) \$\endgroup\$
    – KarlKastor
    Commented Jul 21, 2016 at 11:13
15
\$\begingroup\$

R, 4 bytes

2:10

The ":" is probably one of the most used R commands. Improvement by Barranka in comments.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Should they require printing a string, not returning a vector, consider cat(1:10). \$\endgroup\$ Commented Jul 22, 2016 at 15:54
  • \$\begingroup\$ Is there a leading whitespace? \$\endgroup\$
    – Clashsoft
    Commented Jul 22, 2016 at 18:37
  • 10
    \$\begingroup\$ Given that the output is [1] 1 2 3 4 5 6 7 8 9 10, maybe it would be better 2:10, which will output [1] 2 3 4 5 6 7 8 9 10 \$\endgroup\$
    – Barranka
    Commented Jul 22, 2016 at 19:27
  • \$\begingroup\$ @Clashsoft, that was a mistake - thank you. And yes, Barranka, good point - upvoted. \$\endgroup\$ Commented Jul 22, 2016 at 21:50
  • 1
    \$\begingroup\$ Come on, Prof. Robert, read the comment by Barranka :-) \$\endgroup\$ Commented Nov 19, 2020 at 10:55
14
\$\begingroup\$

Ruby, 8 bytes

Separated by newlines.

p *1..10
\$\endgroup\$
4
  • \$\begingroup\$ *Separated by newlines. \$\endgroup\$ Commented Jul 22, 2016 at 17:06
  • \$\begingroup\$ You can do that? \$\endgroup\$
    – anna328p
    Commented Oct 18, 2016 at 16:38
  • \$\begingroup\$ @DmitryKudriavtsev yes, the star causes the code to break down to p 1,2,3,4,5,6,7,8,9,10 and commas cause p to separate them by newlines. \$\endgroup\$
    – Value Ink
    Commented Oct 18, 2016 at 18:11
  • \$\begingroup\$ OK. I didn't think that the operator has a lower precedence than range. \$\endgroup\$
    – anna328p
    Commented Oct 18, 2016 at 18:37
13
\$\begingroup\$

JavaScript (ES6), 29 bytes

alert([...`${1e11/81^14}`]+0)

Outputs 1,2,3,4,5,6,7,8,9,10. Not the shortest answer but I thought it was a fun calculation.

\$\endgroup\$
2
  • \$\begingroup\$ why not alert([...'1'+234567891]+0) \$\endgroup\$
    – edc65
    Commented Jul 26, 2016 at 18:27
  • 2
    \$\begingroup\$ @edc65 a) it's not as fun b) it's not as short as the previously posted JavaScript answer c) it's not even as short as alert([...'1234567891']+0). \$\endgroup\$
    – Neil
    Commented Jul 26, 2016 at 18:45
13
\$\begingroup\$

Brainfuck, 41 bytes

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

Output

1 2 3 4 5 6 7 8 9 10

Try it online.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice! – – – – – \$\endgroup\$
    – Leaky Nun
    Commented Jul 24, 2016 at 10:56
  • \$\begingroup\$ +.+.+.+.+.+.+.+.+.+. \$\endgroup\$ Commented Jun 24 at 9:44
12
\$\begingroup\$

Pyth, 2 bytes

ST

First time I've used a golfing lang to answer!

Explanation:

S    1-indexed range. [1, 2, ... A].
 T   Variable. Initialized to 10. (Ten)
     Implicitly printed.
\$\endgroup\$
1
  • \$\begingroup\$ Ninja'd by seconds :/ \$\endgroup\$ Commented Jul 21, 2016 at 9:44
11
\$\begingroup\$

Actually, 9 Bytes

19`;1+`na

Try it here!

Explanation:

19`;1+`na

1           Push 1 to stack
 9          Push 9 to stack
  `;1+`     Push Function inside ` to stack
   ;        Push top element to stack
    1+      Add 1 to top element
       n    Run function x times (9 times)
        a   Invert stack
\$\endgroup\$
1
  • 11
    \$\begingroup\$ Welcome to Programming Puzzles and Code Golf! \$\endgroup\$
    – Adnan
    Commented Jul 21, 2016 at 9:29
11
\$\begingroup\$

Mathematica - 13 bytes

Echo@Range@10

Saved 4 bytes thanks to MartinEnder!

Output: >> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

\$\endgroup\$
0
10
\$\begingroup\$

DC, 12 bytes

...a little bit mean now...

[zzpA>L]dsLx

Unrolled:

[   # start string constant
z   # push stack length (0 on 1st cycle)
z   # push stack length (1 on 1st cycle)
p   # print top of stack
A>L # if 10(decimal) < tos: execute L
]   # end string constant, push it
d   # duplicate the string
sL  # store a copy in L
x   # execute tos (which is the other string copy)

One of the z (push stack length) operations has no corresponding operation which takes it from the stack. This way the stack grows with each iteration by one. This is abused as the loop counter.

This loop starts with an empty stack, so the 1st z pushes 0 in the 1st iteration so the printing happens after the 2nd z which correspond to duplicating the result of 1+d in the version below. This way the comparison needs to test for bigger than 10 here instead of bigger than 11 below.


DC, 14 bytes

Just straight forward...

1[p1+dB>L]dsLx

Unrolled:

1   # push 1
[   # start string constant
p   # print top of stack
1+  # add 1 to tos
d   # push tos (duplicate)
B>L # if 11(decimal) < tos: execute L
]   # end string constant, push it
d   # duplicate the string
sL  # store a copy in L
x   # execute tos (which is the other string copy)
\$\endgroup\$
2
  • \$\begingroup\$ I wish you'd explain these =( \$\endgroup\$ Commented Mar 9, 2018 at 22:45
  • \$\begingroup\$ @EvanCarroll — Writing dc programs is easier than explaining. But I tried... ;-) \$\endgroup\$
    – user19214
    Commented Mar 10, 2018 at 6:52
10
\$\begingroup\$

Aussie++, output to STDERR, 29 28 bytes

It turns out that causing errors is shorter than any straightforward way of doing it.

G'DAY MATE! 1 2

4

6

8

_

Tested in commit 9522366. The trailing newline is required. Produces the following errors:

[line 1] OI MATE! EXPECTED ; BUT GOT '2'
[line 3] OI MATE! EXPECTED ; BUT GOT '4'
[line 5] OI MATE! EXPECTED ; BUT GOT '6'
[line 7] OI MATE! EXPECTED ; BUT GOT '8'
[line 9] OI MATE! EXPECTED ; BUT GOT '_'
[line 10] OI MATE! EXPECTED ; BUT GOT 'EOF'

Maybe I misinterpreted the challenge, but it didn't specify that you had to use the same separator for all numbers.

Aussie++, output to STDERR with consistent separator, 30 bytes

G'DAY MATE!;
;
;
;
;
;
;
;
;
;

No trailing newline is required. Produces the following errors:

[line 1] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 2] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 3] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 4] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 5] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 6] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 7] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 8] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 9] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'
[line 10] EXPECTED NUMBER, STRING, BOOLEAN, NIL, OR IDENTIFIER BUT GOT ';'

Aussie++, output to STDOUT, 41 bytes

G'DAY MATE!
GIMME "1 2 3 4 5 6 7 8 9 10";

Again, no trailing newline is required.

\$\endgroup\$
9
\$\begingroup\$

><>, 13 bytes

01+:a)?;:nao!

Explanation :

01+:a)?;:nao!

0                 push initial value of n on the stack
 1+               increments n
   :              duplicates n on the stack
    a             push 10 on the stack
     )            pops n and 10 of the stack, push n>10 on the stack
      ?;          if n>10, stops program execution
        :n        duplicates n on the stack in order to display it
          ao      display 10 (x0A, linefeed)
            !     skips the next instruction, which since ><> loops is the push 0

You can see it in action on the online interpreter.

\$\endgroup\$
3
  • \$\begingroup\$ Could you please add an explanation? \$\endgroup\$
    – Clashsoft
    Commented Jul 21, 2016 at 9:19
  • 1
    \$\begingroup\$ Run the program nao! \$\endgroup\$
    – Cyoce
    Commented Jun 19, 2017 at 18:07
  • \$\begingroup\$ @Cyoce ><> is great to write enthusiastic pieces of code, I've got this motorcycle gear checker answer in the same vein ;) \$\endgroup\$
    – Aaron
    Commented Jun 19, 2017 at 18:21
9
\$\begingroup\$

MATL, 3 bytes

10:

Try it online!

The code generates the vector [1 2 ... 10] and implicitly displays it, with the numbers separated by spaces.

\$\endgroup\$
8
\$\begingroup\$

PowerShell, 5 bytes

1..10

Creates a dynamic range with the .. operator from 1 to 10, then that array is left on the pipeline. Output is implicit. Default .ToString() method of an array is newline, so this will be newline-separated when run in a clean shell.

\$\endgroup\$
8
\$\begingroup\$

Vim, 12 bytes

i1<Esc>qqYp<C-a>q8@q

Outputs

1
2
3
4
5
6
7
8
9
10

Explanation:

i1<Esc>qqYp<C-a>q8@qZZ
       qqYp<C-a>q      -- Macro q: duplicate line and increment (6)
i1<Esc>                -- Insert 1 (3)
                 8@q   -- Run macro q 8 times (3)

Tested on Neovim 0.1.4, which to my knowledge is keystroke-compatible with Vim.

\$\endgroup\$
2
  • \$\begingroup\$ Nice. I came up with iYp<C-v><C-a>1<Esc>d^9@-ZZ. Same byte count. \$\endgroup\$
    – primo
    Commented Jul 24, 2016 at 12:07
  • 3
    \$\begingroup\$ Shorter. :) \$\endgroup\$
    – DJMcMayhem
    Commented Nov 16, 2016 at 21:36
8
\$\begingroup\$

Perl 6, 12 bytes

say @(1..10)

The @() is needed to convert to an array

Alternative solution:

say @(^10+1)

Builds a range [0,10) then adds one, then converts to an array.

\$\endgroup\$
5
  • \$\begingroup\$ For Perl 5.10, 14 bytes and almost like yours: say for(1..10) \$\endgroup\$
    – Sake
    Commented Jul 21, 2016 at 13:50
  • \$\begingroup\$ @PaulPicard do post it! Perl 5 is a different language. \$\endgroup\$
    – Ven
    Commented Jul 21, 2016 at 13:58
  • \$\begingroup\$ Can you remove the space for say@(1..10)? \$\endgroup\$
    – Cyoce
    Commented Jun 23, 2017 at 8:53
  • \$\begingroup\$ @Cyoce alas no, it's an error. \$\endgroup\$
    – Ven
    Commented Jun 23, 2017 at 17:04
  • \$\begingroup\$ 10 bytes: say 1...10 \$\endgroup\$
    – nwellnhof
    Commented Nov 18, 2019 at 12:10
7
\$\begingroup\$

Dyalog APL, 3 bytes

⍳10

TryAPL online!

\$\endgroup\$
1
  • \$\begingroup\$ too long......... \$\endgroup\$
    – Razetime
    Commented Apr 13, 2021 at 17:00
7
\$\begingroup\$

J, 6 bytes

1+i.10

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

Explaination:

1+       NB. Add one to...
  i.10   NB. A range from 0 to 9.
\$\endgroup\$
1
  • \$\begingroup\$ My thought was >:i.10, but that's the same thing. \$\endgroup\$
    – Dane
    Commented Jul 22, 2016 at 21:40
7
\$\begingroup\$

Haskell, 17 bytes

main=print[1..10]

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

\$\endgroup\$
6
  • \$\begingroup\$ I'm a bit confused here... I'm almost certain that it should be [1..10]. I don't have access to a haskell compiler, but I'll double-check in the morning. \$\endgroup\$
    – Zwei
    Commented Jul 21, 2016 at 9:29
  • \$\begingroup\$ @Zwei Ranges don't include their upper limit in Haskell. \$\endgroup\$
    – C. Quilley
    Commented Jul 21, 2016 at 9:43
  • 1
    \$\begingroup\$ @C.Quilley They totally do. You might be thinking of Python. \$\endgroup\$
    – xnor
    Commented Jul 21, 2016 at 9:53
  • \$\begingroup\$ Huh, I was sure I had tested this code. Apologies for the earlier assertion. \$\endgroup\$
    – C. Quilley
    Commented Jul 21, 2016 at 11:04
  • 1
    \$\begingroup\$ I don't think you need the main= part; the rest has the type of a haskell program, IO (). Correct me if there is a specific ruling against this. \$\endgroup\$
    – Lazersmoke
    Commented Aug 16, 2016 at 16:28
7
\$\begingroup\$

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.)

\$\endgroup\$
7
\$\begingroup\$

MarioLANG, 34 27 25 bytes

+<
:"
+
:
+
:
+
:
+
:!
=#

Try it online!

Thanks to Jo King for -7 -9 bytes!

code:

Mario falls down, incrementing and saying his number five times, then he steps on the elevator, rides up and falls down again, incrementing and saying his number another five times. Then he walks left and falls out of the code.

14 bytes shorter than the easy way:

39 bytes

+:+:+:+:+:+:+:+:+:+
==================:

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Thank you. Sometimes you just can't see the forest for the trees. \$\endgroup\$
    – Dorian
    Commented Sep 18, 2019 at 8:12
6
\$\begingroup\$

Fuzzy Octo Guacamole, 7 bytes

1.25*$:

Multiplies 2*5, takes the range of that and 1, and prints the whole stack.

1.25*$:
1.      # Push 1 to the stack and switch stacks
  25*   # Push 10 to the stack
     $  # Push every number in the inclusive range on the top of inactive stack and top of active stack ([1,2,3,4,5,6,7,8,9,10])
      : # Print the stack, which is a list containing the numbers.
\$\endgroup\$
1
  • \$\begingroup\$ I'm sorry, the language is called what?!? \$\endgroup\$
    – SanguineL
    Commented Jun 24 at 14:12
6
\$\begingroup\$

Java 7, 53 51 52 bytes (loop)

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

Alternative 51 bytes (hardcoded is shorter.., but considered a default loophole, so not allowed):

void h(){System.out.print("1 2 3 4 5 6 7 8 9 10");}

Alternative 54 bytes (recursive):

int i=1;void r(){System.out.println(i);if(i++<10)r();}

Ungolfed & test code for all three:

Try it here.

class Main{
  static void h(){
    System.out.print("1 2 3 4 5 6 7 8 9 10");
  }      

  static void l(){
    for(int i=0; ++i < 11;){
      System.out.println(i);
    }
  }

  static int i = 1;
  static void r(){
    System.out.println(i);
    if(i++ < 10){
      r();
    }
  }

  public static void main(String[] a){
    h();
    System.out.println();
    l();
    System.out.println();
    r();
  }
}

EDIT: For funsies: As correctly pointed out by @SkippyLeGrandGourou, the base of the 1 to 10 isn't specified in the question, so here is (non-code-golfed) Java code that outputs 1 to 10 in the bases 2 to 10:

Try it here.

BASE-2: 1 10 
BASE-3: 1 2 10 
BASE-4: 1 2 3 10 
BASE-5: 1 2 3 4 10 
BASE-6: 1 2 3 4 5 10 
BASE-7: 1 2 3 4 5 6 10 
BASE-8: 1 2 3 4 5 6 7 10 
BASE-9: 1 2 3 4 5 6 7 8 10 
BASE-10: 1 2 3 4 5 6 7 8 9 10 
\$\endgroup\$
5
  • \$\begingroup\$ Loop can be for(int i=1;i<11;)System.out.println(i++), saves one byte. \$\endgroup\$
    – Clashsoft
    Commented Jul 21, 2016 at 9:23
  • \$\begingroup\$ @zyabin101 Changed the order so the hard-coded answer is non-competing. Still left it in the answer though, since it's pretty funny (and sad) that hard-coded is the shortest way to print 1-10 in Java 7.. \$\endgroup\$ Commented Jul 21, 2016 at 10:00
  • 2
    \$\begingroup\$ @zyabin101 Except when the question is tagged kolmogorov-complexity. \$\endgroup\$
    – Neil
    Commented Jul 22, 2016 at 19:43
  • \$\begingroup\$ @Neil Oh, right. o_o \$\endgroup\$
    – user48538
    Commented Jul 22, 2016 at 19:49
  • 1
    \$\begingroup\$ Java 8's the clear winner here thanks to lambdas! ()->java.util.stream.IntStream.range(1,11).forEach(System.out::println). Why you say it's longer? It's Java 8... Java 8 is shorter by default! I didn't even put braces before and after the code! I can even count to 98 without getting an extra character! See? Java 8 rules! \$\endgroup\$ Commented Jun 23, 2017 at 8:39
5
\$\begingroup\$

Retina, 13 bytes

I've got two solutions at this byte count, but it doesn't seem optimal:


_10$*
1
$.`_

11$*_
\B
$.`

They both use _ as separators, prefix and suffix.

Try the first online! Or try the other one!

\$\endgroup\$
1
2 3 4 5
10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.