38
\$\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\$
  • 9
    \$\begingroup\$ Related (duplicate?) \$\endgroup\$ – Luis Mendo Jul 21 '16 at 9:07
  • 15
    \$\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\$ – Peter Taylor Jul 21 '16 at 9:54
  • 9
    \$\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\$ – Martin Ender Jul 21 '16 at 10:01
  • 16
    \$\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 Jul 21 '16 at 14:09
  • 9
    \$\begingroup\$ I can't believe every single of the (currently) 71 answers assumes the base should be decimal… \$\endgroup\$ – Skippy le Grand Gourou Jul 22 '16 at 15:05

204 Answers 204

4
\$\begingroup\$

PHP, 25 23 bytes

Saved 2 bytes thanks to manatwork.

 <?=join(_,range(1,10));

Creates an array of [1 .. 10] and echoes the values separated by _s.

\$\endgroup\$
  • \$\begingroup\$ You could take advantage of the freedom to choose the separator. Using “_” as Martin Ender's Retina solution does would reduce the length by 2. (At the obvious price of an undefined constant notice, which is fine as PHP's suggested production configuration not displays notices anyway.) \$\endgroup\$ – manatwork Jul 21 '16 at 14:08
  • \$\begingroup\$ @manatwork: That is very strange, I had no idea that was even possible. Thanks for the suggestion! \$\endgroup\$ – Business Cat Jul 21 '16 at 14:16
  • \$\begingroup\$ Same length: for(;$i++<10;)echo$i,_; \$\endgroup\$ – Ismael Miguel Jul 22 '16 at 2:36
  • \$\begingroup\$ @IsmaelMiguel: That's longer because it requires the full <?php and not just <?= \$\endgroup\$ – Business Cat Jul 22 '16 at 12:38
  • 1
    \$\begingroup\$ True. and the join(_ is prettier anyway; just keep it like that. But let me add two variations of Ismael´s idea: while($i<10)echo++$i,_; and while(++$i%11)echo$i,_; (same length, but with -r) \$\endgroup\$ – Titus Jul 22 '16 at 14:12
4
\$\begingroup\$

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,
              ;instead of characters.
add 10        ;now the tape is [10,0,...]
jmp           ;start of loop
              ;sets an entry marker and jump to the jnz instruction.
    fwd 1          ;forward the data head 
    add 1          ;add 1 to the cell under 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).

\$\endgroup\$
4
\$\begingroup\$

Plain TeX (58 bytes)

\newcount\c\loop\advance\c1 \the\c\ \ifnum\c<10\repeat\bye

enter image description here

\$\endgroup\$
4
\$\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\$
4
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟, 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)

\$\endgroup\$
  • \$\begingroup\$ 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). \$\endgroup\$ – Mama Fun Roll Aug 2 '16 at 15:05
  • \$\begingroup\$ @MamaFunRoll Yeah, ESMin is awesome! Thanks for the tip. \$\endgroup\$ – emiflake Aug 2 '16 at 15:07
4
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ show([1:10]) is 12 bytes, not 13. That needs to be fixed in the header. \$\endgroup\$ – user48538 Jul 21 '16 at 13:32
3
\$\begingroup\$

Atari Basic, 29 Bytes

1 for i=1 to 10
2 ? i
3 next i
\$\endgroup\$
  • \$\begingroup\$ 1 for i=1 to 10:? i:next is probably more concise? I'm certain that Atari BASIC allows multi-statemented lines \$\endgroup\$ – Shaun Bebbers Mar 9 '18 at 10:30
  • \$\begingroup\$ Also if Atari BASIC is similar to Commodore (Microsoft) BASIC, you won't need to say next i - simply next \$\endgroup\$ – Shaun Bebbers Mar 9 '18 at 10:31
3
\$\begingroup\$

MATLAB/Octave, 4 bytes

1:10

Simply prints the numbers 1 through 10 as a vector, with spaces separating them (may have newline if your window is not wide enough)

\$\endgroup\$
  • 3
    \$\begingroup\$ Does it matter that this also outputs ans = ? You may need to wrap it in a disp \$\endgroup\$ – Suever Jul 22 '16 at 1:59
  • 1
    \$\begingroup\$ @Suever no, I don't think so. "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 [...]). However, you may not output any other numbers." There are no extra digits or numbers. \$\endgroup\$ – bers Jul 23 '16 at 18:24
3
\$\begingroup\$

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==

\$\endgroup\$
3
\$\begingroup\$

Excel 6 bytes

=ROW(

Select the cells A1:A10, type the above (once only) and ctrl-shift-enter as an array formula (which links the cells in an array, with one common formula).

Note the total lack of numerals entered in this process. :-)

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Not sure this is allowed. It requires a specific state (A1:A10 selected) and input (1,2,3,4,5,6,7,8,9,10) \$\endgroup\$ – Cyoce Sep 2 '16 at 0:45
  • \$\begingroup\$ @Cyoce It doesn't require any numeric input. The range selection could potentially be specified with f5 A1:A10 enter which would be 8 more keystrokes. \$\endgroup\$ – Joffan Sep 2 '16 at 16:25
3
\$\begingroup\$

ShadyAsFuck, 10 9 bytes

PPPPPz_G]

This is basically ++++++++++[>+.<-] in BrainFuck and outputs the numerical values as character codes.

Try It Online!

\$\endgroup\$
  • \$\begingroup\$ Removing a byte: PPPPPz_G] \$\endgroup\$ – Addison Crump Aug 2 '16 at 20:13
3
\$\begingroup\$

T-SQL, 53 46 Bytes

Saved 7 bytes thanks to @t-clausen.dk

DECLARE @ INT=1z:PRINT @ SET @+=1IF @<11GOTO z

Also 17 bytes (though it feels like cheating):

PRINT 12345678910
\$\endgroup\$
  • \$\begingroup\$ Can be done easier, here are 2 examples - fiddle \$\endgroup\$ – t-clausen.dk Aug 29 '16 at 9:31
3
\$\begingroup\$

Stata, 40 bytes

loc i=1
wh `i'<11 {
di `i'
loc i=`i'+1
}

Output

1
2
3
4
5
6
7
8
9
10
\$\endgroup\$
  • \$\begingroup\$ Hello, and welcome to PPCG! Do you need all the whitespace? \$\endgroup\$ – NoOneIsHere Sep 1 '16 at 17:36
  • \$\begingroup\$ Thank you. Yes, the whitespace is required, alas. \$\endgroup\$ – f1rstguess Sep 1 '16 at 17:43
  • \$\begingroup\$ You can use a global (gl) instead of local. Then you access the variable with $i. That should save some bytes. I'm happy to find another STATA user on PPCG! \$\endgroup\$ – bmarks Feb 17 '17 at 5:06
3
\$\begingroup\$

Morse code, 65 bytes

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

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

\$\endgroup\$
3
\$\begingroup\$

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.

And though I very much like re-using ops, this time I left a lot of no-ops and used a lot of $ skip commands to keep the loop running.

Oh I really love this language!

\$\endgroup\$
3
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ huh. Didn't know about the g<C-a> trick. GG. \$\endgroup\$ – Zwei Nov 17 '16 at 2:23
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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)                                                  
  10:   00 01                   add    %al,(%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.

\$\endgroup\$
3
\$\begingroup\$

Brainfuck, 53 bytes

++++++++[->++++++>+>++++<<<]>>+[-<+.>>.<]<--------.-.
\$\endgroup\$
3
\$\begingroup\$

Whitespace,

71 bytes, thanks to LeakyNun,

63 bytes, thanks to Kevin

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

(extra spaces inserted for readability)

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
\$\endgroup\$
  • \$\begingroup\$ @LeakyNun Ok, i'll update the code. I used Notepad++ for the bytecount. \$\endgroup\$ – ABcDexter Jul 24 '16 at 8:42
  • 1
    \$\begingroup\$ You can save a lot of bytes by changing the two labels to just one byte. \$\endgroup\$ – Leaky Nun Jul 24 '16 at 9:35
  • 1
    \$\begingroup\$ i.e. here: SSSTL LSSTL SLS TLST SSSTSTSL TLS SSSSTL TSSS SLS SSSTSTTL TSST LTSSL LSLTL LSSSL LLL \$\endgroup\$ – Leaky Nun Jul 24 '16 at 9:37
  • 1
    \$\begingroup\$ that would be 71 bytes \$\endgroup\$ – Leaky Nun Jul 24 '16 at 9:40
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – Kevin Cruijssen Mar 13 '18 at 20:28
3
\$\begingroup\$

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]
 TSSS       Add (1+1)                  [2]
 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]
 NTTSN      Jump to Label_1 if neg.    [2]
 NSNN       Jump to Label_LOOP         [2]

 SNS        Duplicate (2)              [2,2]
 TNST       Print as integer           [2]             2
 SSSTN      Push 1                     [2,1]
 TSSS       Add (2+1)                  [3]
 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]
 NTTSN      Jump to Label_1 if neg.    [3]
 NSNN       Jump to Label_LOOP         [3]

 ...

 SNS        Duplicate (9)              [9,9]
 TNST       Print as integer           [9]             9
 SSSTN      Push 1                     [9,1]
 TSSS       Add (9+1)                  [10]
 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]
 NTTSN      Jump to Label_1 if neg.    [10]
 NSNN       Jump to Label_LOOP         [10]

 SNS        Duplicate (10)             [10,10]
 TNST       Print as integer           [10]            10
 SSSTN      Push 1                     [10,1]
 TSSS       Add (10+1)                 [11]
 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]
 NTTSN      Jump to Label_1 if neg.    [11]                     Label_1 not found error
\$\endgroup\$
2
\$\begingroup\$

Lua, 25 Bytes

for i=1,10 do print(i)end
\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ 5 bytes: 10yb. \$\endgroup\$ – mat Jul 21 '16 at 11:57
  • \$\begingroup\$ @mat Thanks, I didn't thought of that, even though it's even simpler! \$\endgroup\$ – Fatalize Jul 21 '16 at 12:00
2
\$\begingroup\$

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!

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

Brainfuck, 66 Bytes

Sadly, Someone found a 58 Bytes solution, but as we both have different way of solving this, I'll post mine anyway.

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

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

Here's what the tape looks like at each step, the * shows where the pointer lies.

+++[>+++>++<<-] tape (0*:9:6)cell-2: counter for printing;cell-3: used for ascii-value of 1
>>+[>+++++++<-] tape (0:9:0*:49) 49 is the ascii value of 1
>[>+>+<<-<+>]   tape (0:9:49:0*:49:49) duplicate it 3 times
<--<            tape (0:9*:47:0:49:49) one will be used as a delimiter "/"
[>>>.+<<.<-]    tape (0:0*:47:0:57:49) outputs the numbers 1..9 separated by "/"
>>>>.-.         tape (0:0:47:0:49:48) outputs 10
\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 29 bytes

(dotimes(n 10)(print(+ n 1)))
\$\endgroup\$
  • 2
    \$\begingroup\$ Perhaps this would save 1 byte? (dotimes(n 10)(print(1+ n))) \$\endgroup\$ – gsl Jul 23 '16 at 8:11
2
\$\begingroup\$

Convex, 3 bytes

A´`

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Swift 3 (Jun 20, 2016), 20 bytes

print(Array(1...10))

Try it online!

Just doing print(1...10) (un)surprisingly prints 1...10 to STDOUT, so we need to unwrap the Range object into an Array. A Set would be shorter, but does not guarantee order (and in practice doesn't, either).

\$\endgroup\$
2
\$\begingroup\$

Julia 0.2, 11 bytes

print(1:10)

Pretty self explanatory. 1:10 is a range, and print expands it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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