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
5
\$\begingroup\$

JavaScript, 25 24 bytes

for(i=1;i<11;)alert(i++)
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to PPCG! I think you can save a byte by doing alert(i++) (and removing the other i++). \$\endgroup\$ Commented Jul 21, 2016 at 14:00
  • \$\begingroup\$ Too bad the question stipulates that the order must be ascending, otherwise you could've saved a byte by using a decrementing while loop instead of the for loop like so i=10;while(i)alert(i--). \$\endgroup\$
    – kamoroso94
    Commented Aug 2, 2016 at 14:43
  • \$\begingroup\$ Doesn't the code have to be embedded in a function? \$\endgroup\$
    – ericw31415
    Commented Jun 15, 2017 at 21:04
  • \$\begingroup\$ @ericw31415 codegolf.meta.stackexchange.com/a/2422/56627 \$\endgroup\$
    – Kruga
    Commented Jun 16, 2017 at 7:53
5
\$\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\$
9
  • \$\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
    Commented Jul 21, 2016 at 14:08
  • \$\begingroup\$ @manatwork: That is very strange, I had no idea that was even possible. Thanks for the suggestion! \$\endgroup\$ Commented Jul 21, 2016 at 14:16
  • \$\begingroup\$ Same length: for(;$i++<10;)echo$i,_; \$\endgroup\$ Commented Jul 22, 2016 at 2:36
  • \$\begingroup\$ @IsmaelMiguel: That's longer because it requires the full <?php and not just <?= \$\endgroup\$ Commented Jul 22, 2016 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
    Commented Jul 22, 2016 at 14:12
5
\$\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\$
2
  • 3
    \$\begingroup\$ Does it matter that this also outputs ans = ? You may need to wrap it in a disp \$\endgroup\$
    – Suever
    Commented Jul 22, 2016 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
    Commented Jul 23, 2016 at 18:24
5
\$\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\$
5
\$\begingroup\$

Plain TeX (58 bytes)

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

enter image description here

\$\endgroup\$
5
\$\begingroup\$

Python2 - 19 17 bytes

print range(1,11)

Saved 1 byte, thanks to KevinLau - not Kenny!

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

\$\endgroup\$
9
  • \$\begingroup\$ Use range instead of xrange, assuming Python 2. In fact, this current version doesn't seem to work on my machine in either Python version. \$\endgroup\$
    – Value Ink
    Commented Jul 21, 2016 at 9:18
  • \$\begingroup\$ @KevinLau-notKenny I could've sworn that I tried that, and got nothing to STDOUT. Thanks! \$\endgroup\$
    – Yytsi
    Commented Jul 21, 2016 at 9:20
  • \$\begingroup\$ Important: It's only Python 2 \$\endgroup\$
    – univalence
    Commented Jul 23, 2016 at 18:47
  • 1
    \$\begingroup\$ @ABcDexter I checked it out, very nice! The reason I didn't use Python3, was because I was forced to cast the range object that returns an iterator, to a list. \$\endgroup\$
    – Yytsi
    Commented Jul 23, 2016 at 19:39
  • 1
    \$\begingroup\$ @TuukkaX Yes, exactly. I'll try some other languages too. Thanks :). \$\endgroup\$
    – ABcDexter
    Commented Jul 23, 2016 at 19:44
5
\$\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\$
4
\$\begingroup\$

Groovy, 11 characters

print 1..10

Sample run:

bash-4.3$ groovy -e 'print 1..10'
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
\$\endgroup\$
4
\$\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\$
1
  • \$\begingroup\$ show([1:10]) is 12 bytes, not 13. That needs to be fixed in the header. \$\endgroup\$
    – user48538
    Commented Jul 21, 2016 at 13:32
4
\$\begingroup\$

Atari Basic, 29 Bytes

1 for i=1 to 10
2 ? i
3 next i
\$\endgroup\$
2
  • \$\begingroup\$ 1 for i=1 to 10:? i:next is probably more concise? I'm certain that Atari BASIC allows multi-statemented lines \$\endgroup\$ Commented Mar 9, 2018 at 10:30
  • 1
    \$\begingroup\$ Also if Atari BASIC is similar to Commodore (Microsoft) BASIC, you won't need to say next i - simply next \$\endgroup\$ Commented Mar 9, 2018 at 10:31
4
\$\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\$
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\$
2
  • \$\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\$ Commented Aug 2, 2016 at 15:05
  • \$\begingroup\$ @MamaFunRoll Yeah, ESMin is awesome! Thanks for the tip. \$\endgroup\$
    – emiflake
    Commented Aug 2, 2016 at 15:07
4
\$\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\$
1
  • \$\begingroup\$ Can be done easier, here are 2 examples - fiddle \$\endgroup\$ Commented Aug 29, 2016 at 9:31
4
\$\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\$
4
\$\begingroup\$

Hexagony, 31 bytes

<8!~\\\..)\M\~={{'$;[email protected]$

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

Brainfuck, 53 bytes

++++++++[->++++++>+>++++<<<]>>+[-<+.>>.<]<--------.-.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Commented Feb 20, 2018 at 14:52
  • \$\begingroup\$ Try it online! \$\endgroup\$
    – Dennis
    Commented Feb 21, 2018 at 2:57
4
\$\begingroup\$

Brian & Chuck, 17 bytes

1	1{?
!{.+>-?>.-.

Try it online!

code:

Brian:
1   1   ("1", 9, "1") constants
{?      restart Chuck's code

Chuck:  
{       Move Brian to the leftmost character
.+      Print and increment character
>-      decrement counter
?       if counter is greater than zero, switch to Brian (restart Chuck's code)
>.-.    print 10
\$\endgroup\$
4
\$\begingroup\$

RUBY, 24 bytes 18 bytes

n=0;10.times{puts n+=1}

thanks to @A_

10.times{|n|p n+1}
\$\endgroup\$
1
  • \$\begingroup\$ 18 bytes \$\endgroup\$
    – user85052
    Commented Nov 18, 2019 at 8:17
3
\$\begingroup\$

Elixir, 18 bytes

for n<-1..10,do: n

Output:

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

Note: This is using iex, the Elixir REPL.

\$\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\$
2
  • 1
    \$\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
    Commented Sep 2, 2016 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
    Commented Sep 2, 2016 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\$
1
  • \$\begingroup\$ Removing a byte: PPPPPz_G] \$\endgroup\$ Commented Aug 2, 2016 at 20:13
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\$
3
  • \$\begingroup\$ Hello, and welcome to PPCG! Do you need all the whitespace? \$\endgroup\$ Commented Sep 1, 2016 at 17:36
  • \$\begingroup\$ Thank you. Yes, the whitespace is required, alas. \$\endgroup\$
    – f1rstguess
    Commented Sep 1, 2016 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
    Commented Feb 17, 2017 at 5:06
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\$

Sinclair ZX80 (4/8K ROM) or Sinclair ZX81/ZX Spectrum (27 tokenized BASIC bytes for the ZX80, 38 tokenized BASIC bytes for the ZX81)

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

Or (direct mode, probably works on all 8-bit variants of BASIC):

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

Sinclair ZX Spectrum (and other BASIC variants except the ZX80/ZX81):

 1 FOR I=1 TO 10:PRINT I:NEXT I

Simple, no?

\$\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\$
7
  • \$\begingroup\$ @LeakyNun Ok, i'll update the code. I used Notepad++ for the bytecount. \$\endgroup\$
    – ABcDexter
    Commented Jul 24, 2016 at 8:42
  • 1
    \$\begingroup\$ You can save a lot of bytes by changing the two labels to just one byte. \$\endgroup\$
    – Leaky Nun
    Commented Jul 24, 2016 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
    Commented Jul 24, 2016 at 9:37
  • 1
    \$\begingroup\$ that would be 71 bytes \$\endgroup\$
    – Leaky Nun
    Commented Jul 24, 2016 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\$ Commented Mar 13, 2018 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\$
3
\$\begingroup\$

Factor, 15 bytes

10 [1,b] stack.

Try it online!

  • 10 [1,b] Create the range [1,10].
  • stack. Prettyprint each element of a sequence.
\$\endgroup\$
3
  • \$\begingroup\$ The challenge spec is forgiving enough, so simply printing the array with . seems OK. \$\endgroup\$
    – Bubbler
    Commented Apr 27, 2021 at 1:27
  • \$\begingroup\$ @Bubbler That's not an array. :) \$\endgroup\$
    – chunes
    Commented Apr 27, 2021 at 1:28
  • \$\begingroup\$ Oh, my bad. So stack. is indeed the shortest way to (implicitly cast and) print it I guess. \$\endgroup\$
    – Bubbler
    Commented Apr 27, 2021 at 1:29
3
\$\begingroup\$

dotcomma, 67 bytes

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

Try it online!

A simple approach which nests [[...][.].,], which adds one to and then pushes each number from one to ten. The "root" of this is [.,] which pushes one.

Explanation:

In dotcomma, dots and commas are the only operators. Their behaviors are extremely context dependent; . will be 1 when preceded [, or it can be used for adding, or it can be used in a loop, or a conditional.

In the case of [.,], the . is a constant for 1, and the , takes that and pushes it to the stack. After this, [.] is another 1 constant, wrapped in a block. The . after this takes the previous blocks, [.,] and [.], and adds them. This results in 2, which is pushed by ,. This is nested with another [.].,, which continues up to 10.

\$\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.