51
\$\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
    Jul 21 '16 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\$ Jul 21 '16 at 9:54
  • 10
    \$\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\$ Jul 21 '16 at 10:01
  • 19
    \$\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
  • 10
    \$\begingroup\$ I can't believe every single of the (currently) 71 answers assumes the base should be decimal… \$\endgroup\$ Jul 22 '16 at 15:05

244 Answers 244

1 2 3
4
5
9
2
\$\begingroup\$

Hexadecimal Stacking Pseudo-Assembly Language, 54 bytes

203039400000120000201A8540000012000020000A400000120000

Try it online!

203039 input 0x3039 (decimal 12345)
400000 push that on stack
120000 print it
201A85 input 0x1A85 (decimal 6789)
400000 push that on stack
120000 print it
20000A input 0xA (decimal 10)
400000 push that on stack
120000 print it
\$\endgroup\$
2
\$\begingroup\$

BrainFuck, 41 Bytes

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

Output

12345678910

Try it online

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

naz, 50 bytes

1x1f1a1o2x1v0m9a1a1o1v0x1f1f1f1f1f1f1f1f1f8s1o1s1o

Explanation (with 0x commands removed)

1x1f                   # Function 1
    1a1o               # Add 1 to the register and output
        2x1v           # Store the new value in variable 1
            0m9a1a1o   # Output a newline
                    1v # Read variable 1 into the register
1f1f1f1f1f1f1f1f1f     # Call function 1 nine times
8s1o                   # Subtract 8 and output
1s1o                   # Subtract 1 and output
\$\endgroup\$
2
\$\begingroup\$

Commodore BASIC, method 1 (28 bytes)

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

Method 2 (27 26 bytes)

0FORI=1TO10:?I:NEXT

Method 3 (40 39 bytes)

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

Method 4 (32 31 bytes)

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

Method 5 (20 bytes)

0?"12345678910

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

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

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

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

Flurry, 38 bytes

<({<({})({}){}>}){}>{(<><<>()>{})}({})

Verification

$ ./flurry -inn -c "<({<({})({}){}>}){}>{(<><<>()>{})}({})"
1 2 3 4 5 6 7 8 9 10

Since multiplication and exponentiation is much cheaper than increment, addition, and high number literals, 9 (being 3**2 or 3*3) is much cheaper to produce than 10. Since producing 1 is almost free (via popping from empty stack), I push a 1 manually and then loop 9 times to push 2 through 10. Then the stack is printed in integer mode, from bottom to top.

<({<({})({}){}>}){}>  Number 9
<...>  Function composition (multiply numbers)
 (...)  Push and return the number inside...
  {<({})({}){}>}  The number literal 3
 {}     Pop 3 back
       evaluates to 3 * 3 = 9

{(<><<>()>{})}  Lambda function: Increment, push and return
{...}  Lambda, which implicitly pushes its argument
 (...)  Push and return the result of...
  <><<>()>  Increment
  {}        the argument

({})  Initial value 1, pushed to the stack

The entire program is roughly 9 (\x. push (succ x)) (push 1)
\$\endgroup\$
2
\$\begingroup\$

Grok, 13 bytes

}q
{p1+YzP9>!
\$\endgroup\$
2
\$\begingroup\$

Vyxal, 2 bytes

₀ɾ

Try it Online!

Explanation:

₀   # 10
 ɾ  # Range [1, N]
    # Implicit output
\$\endgroup\$
2
\$\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
    Apr 27 at 1:27
  • \$\begingroup\$ @Bubbler That's not an array. :) \$\endgroup\$
    – chunes
    Apr 27 at 1:28
  • \$\begingroup\$ Oh, my bad. So stack. is indeed the shortest way to (implicitly cast and) print it I guess. \$\endgroup\$
    – Bubbler
    Apr 27 at 1:29
1
\$\begingroup\$

Bubblegum, 17 bytes

00000000: 026f eafc 0f98 211e 5d50 d0aa 25bc 6f2a  .o....!.]P..%.o*
00000010: d1                                       .

Outputs 1 2 3 4 5 6 7 8 9 10. The program is compressed using BB96, whereas other schemes are longer due to compression-format headers.

\$\endgroup\$
1
\$\begingroup\$

PHP, 20 bytes

1 2 3 4 5 6 7 8 9 10

Standard output is implicit outside of PHP tags when reading from a file or standard input.

I'm assuming that an empty separator does not meet the 'arbitrary separator' constraint.

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

Pyke, 2 bytes

TS

Try it here!

one_range(10)
\$\endgroup\$
1
\$\begingroup\$

ListSharp, 37 bytes

[FOREACH NUMB IN 1 TO 10 AS i]
SHOW=i

Pretty straight forward

as a sidenote => is this cheating?

SHOW="10,9,8,7,6,5,4,3,2,1"
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hardcoding the output is a standard loophole. \$\endgroup\$
    – Neil
    Jul 21 '16 at 19:04
  • \$\begingroup\$ "Often, this vulnerability is an indicator of a dumb question" \$\endgroup\$ Jul 21 '16 at 19:27
  • 1
    \$\begingroup\$ @Neil, except kolmogorov-complexity. \$\endgroup\$
    – Qwertiy
    Jul 22 '16 at 19:34
1
\$\begingroup\$

Racket, 15 bytes

(cdr(range 11))

Racket's interpreters implicitly print return values of expressions to standard output, which is nice.

\$\endgroup\$
1
\$\begingroup\$

Lua, 26 bytes

for i=1,10 do print(i) end

Prints them in seperate lines.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Duplicate of Katenkyo's answer posted ~9 hours earlier. \$\endgroup\$
    – manatwork
    Jul 22 '16 at 8:37
1
\$\begingroup\$

Excel VBA, 47 Bytes

Sub t()
For i = 1 To 10: MsgBox i: Next
End Sub
\$\endgroup\$
1
  • \$\begingroup\$ You can lose 9 bytes by condensing your whitespace down and removing the () following Sub to Sub t For i=1To 10:MsgBox i:Next End Sub \$\endgroup\$ Mar 25 '17 at 20:51
1
\$\begingroup\$

Scala, 14 bytes

print(1 to 10)

output

Range(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
\$\endgroup\$
1
\$\begingroup\$

Racket, 12 bytes

(range 1 11)

Prints '(1 2 3 4 5 6 7 8 9 10).

\$\endgroup\$
1
\$\begingroup\$

Element, 13 bytes

10'[1+2:`\
`]

Try it online

This outputs one number per line with a trailing newline. This can be shorted to 12 bytes if I replace the newline with a letter (like the letter x). It works by creating a FOR loop, which repeatedly increments the top of the stack, duplicates it, and outputs it.

\$\endgroup\$
1
  • \$\begingroup\$ Nice! You're in your element! :D \$\endgroup\$
    – mbomb007
    Jul 21 '16 at 21:16
1
\$\begingroup\$

Go, 73 bytes

package main 
import "fmt"
func main(){for i:=1;i<11;i++{fmt.Println(i)}}

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Hello, and welcome to PPCG! This is a great first post. \$\endgroup\$ Jul 21 '16 at 21:03
  • \$\begingroup\$ Normally, we use a header like I edited in with the number of bytes in your submission. \$\endgroup\$ Jul 21 '16 at 21:05
1
\$\begingroup\$

JS, 75 Bytes

a=[0,1,2,3,4,5,6,7,8,9,10]; for(a[0];a[0]<a.length;a[0]++){alert(a[a[0]]);}

\$\endgroup\$
1
\$\begingroup\$

Befunge, 14 * 3 - 1 = 41 bytes

0v          <
 >:1+::.55+-|
            @

Quick and dirty befunge '93 solution. I'm sure it could be improved, maybe I'll look into it tomorrow. 41 bytes is the 14 * 3 grid in total, excluding a final newline, there are actually 16 characters in the source.

\$\endgroup\$
0
1
\$\begingroup\$

Befunge-93, 12 bytes

1::.9`#@_1+#

Explanation:

1             Start stack with the number 1
  :.          Print the number on top of the stack
 :  9`        Set (number on top of the stack) > 9
      #       Skip the next character, which would otherwise stop the program
        _     Is the number in the top of the stack true (i.e. not 0)?
       @      If yes, stop the program
         1+   If no, add 1 to the top of the stack
           #  Skip the next character. Since we're at the edge of the program,
              it would wrap to the beginning, so the character being skipped is
              the "1" at the left edge. That is, "don't put 1 on the stack again"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ 10 bytes \$\endgroup\$
    – Jo King
    Feb 1 '18 at 2:12
1
\$\begingroup\$

F# 17 bytes

Equal to Haskell !! yuppee.

printf"%A"[1..10]

Output:

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

For each number on a separate line, 28 bytes:

Seq.iter(printfn"%d")[1..10]

If you remove the standard output permission, simply [1..10] prints out the numbers in F# interactive.

[1..10];;
> val it : int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
\$\endgroup\$
1
\$\begingroup\$

Maple, 10 bytes

seq(1..10)

Output:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10
\$\endgroup\$
1
\$\begingroup\$

Linux ASM, 52 Bytes

file format elf32-i386


Disassembly of section .text:

08048060 <_start>:
 8048060:   31 c9                   xor    ecx,ecx
 8048062:   31 db                   xor    ebx,ebx
 8048064:   31 d2                   xor    edx,edx
 8048066:   31 ff                   xor    edi,edi
 8048068:   43                      inc    ebx
 8048069:   66 81 c7 20 31          add    di,0x3120
 804806e:   57                      push   edi
 804806f:   89 e7                   mov    edi,esp
 8048071:   42                      inc    edx
 8048072:   42                      inc    edx
 8048073:   83 c1 0a                add    ecx,0xa

08048076 <loc_16h>:
 8048076:   87 cf                   xchg   edi,ecx
 8048078:   31 c0                   xor    eax,eax
 804807a:   83 c0 04                add    eax,0x4
 804807d:   83 ff 01                cmp    edi,0x1
 8048080:   75 08                   jne    804808a <loc_2ah>
 8048082:   c7 04 24 20 31 30 ff    mov    DWORD PTR [esp],0xff303120
 8048089:   42                      inc    edx

0804808a <loc_2ah>:
 804808a:   cd 80                   int    0x80
 804808c:   66 ff 41 01             inc    WORD PTR [ecx+0x1]
 8048090:   87 cf                   xchg   edi,ecx
 8048092:   e2 e2                   loop   8048076 <loc_16h> 
\$\endgroup\$
1
\$\begingroup\$

golflua, 13 characters

(Rewrite of Katenkyo's Lua answer. Appreciations should be expressed by upvoting the original answer.)

~@i=1,10w(i)$

Sample run:

bash-4.3$ golflua -e '~@i=1,10w(i)$'
1
2
3
4
5
6
7
8
9
10
\$\endgroup\$
1
\$\begingroup\$

Verbosy 31 Bytes

~0 /0 ~10 /1 :a: ^0 o \0 -1 >-a

Verbosy is a language that I wrote btw. The explanation can be found in README.md.

\$\endgroup\$
1
\$\begingroup\$

JavaScript with UnderscoreJS, 20 Bytes

alert(_.range(1,11))
\$\endgroup\$
2
  • \$\begingroup\$ A similar solution was posted here. Posting a comment suggesting a byte improvement may be a good option next time :) \$\endgroup\$
    – Swivel
    Jul 22 '16 at 20:16
  • \$\begingroup\$ That´s not one byte, that´s 50%. \$\endgroup\$
    – Titus
    Jul 28 '17 at 5:36
1
\$\begingroup\$

LOLCODE, 67 55 bytes

VISIBLE 1 AN 2 AN 3 AN 4 AN 5 AN 6 AN 7 AN 8 AN 9 AN 10
\$\endgroup\$
10
  • 2
    \$\begingroup\$ VISIBLE "1 2 3 4 5 6 7 8 9 10" is only 30 bytes. \$\endgroup\$
    – Leaky Nun
    Jul 22 '16 at 16:52
  • \$\begingroup\$ Oh wow. i'm dumb. \$\endgroup\$ Jul 22 '16 at 16:57
  • 2
    \$\begingroup\$ Is there any difference in the result? \$\endgroup\$
    – Leaky Nun
    Jul 22 '16 at 16:59
  • 1
    \$\begingroup\$ Alright, it's a loophole anyway. \$\endgroup\$
    – Leaky Nun
    Jul 22 '16 at 17:01
  • 1
    \$\begingroup\$ This is kolmogorov-complexity which is an exception to the loophole, right? \$\endgroup\$ Jul 22 '16 at 17:03
1
\$\begingroup\$

JShell (Java 9), 37 36 bytes

for(int i=1;i<11;i++)printf("%d ",i)

Java 9 has a REPL called JShell. You'll need an early access build of Java 9 to run it. Once it's installed, just run jshell, paste, and voilà !

Realized after looking at other solutions that newlines aren't a requirement. Saved 1 byte.

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

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.