117
\$\begingroup\$

In this challenge, you should write a program or function which takes no input and prints or returns a string with the same number of bytes as the program itself. There are a few rules:

  • You may only output bytes in the printable ASCII range (0x20 to 0x7E, inclusive), or newlines (0x0A or 0x0D).
  • Your code must not be a quine, so the code and the output must differ in at least one byte.
  • Your code must be at least one byte long.
  • If your output contains trailing newlines, those are part of the byte count.
  • If your code requires non-standard command-line flags, count them as usual (i.e. by adding the difference to a standard invocation of your language's implementation to the byte count), and the output's length must match your solution's score. E.g. if your program is ab and requires the non-standard flag -n (we'll assume it can't be combined with standard flags, so it's 3 bytes), you should output 5 bytes in total.
  • The output doesn't always have to be the same, as long as you can show that every possible output satisfies the above requirements.
  • Usual quine rules don't apply. You may read the source code or its size, but I doubt this will be shorter than hardcoding it in most languages.

You may write a program or a function and use any of the standard methods of providing output. Note that if you print the result, you may choose to print it either to the standard output or the standard error stream, but only one of them counts.

You may use any programming language, but note that these loopholes are forbidden by default.

This is , so the shortest valid answer – measured in bytes – wins.

Leaderboard

var QUESTION_ID=121056,OVERRIDE_USER=8478;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){var F=function(a){return a.lang.replace(/<\/?a.*?>/g,"").toLowerCase()},el=F(e),sl=F(s);return el>sl?1:el<sl?-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>

asked May 17, 2017 at 11:17
\$\endgroup\$
20
  • 2
    \$\begingroup\$ Related. Related. \$\endgroup\$ Commented May 17, 2017 at 11:19
  • 1
    \$\begingroup\$ @Mr.Xcoder Yes, if you declare them as such. \$\endgroup\$ Commented May 17, 2017 at 16:25
  • 1
    \$\begingroup\$ @DJMcMayhem I figured that in many esolangs it's trivial to print a null byte with one byte of code or similar things, and thought it would lead to more interesting answers if the results were actually readable. \$\endgroup\$ Commented May 17, 2017 at 16:45
  • 4
    \$\begingroup\$ @MartinEnder You should probably disallow output by exit code, which is a default. If you allow it nearly every one byte program in nearly every language is allowed. One user has already done this \$\endgroup\$ Commented May 17, 2017 at 22:37
  • 2
    \$\begingroup\$ @WheatWizard output by exit code is not a string, so it doesn't apply here. \$\endgroup\$ Commented May 18, 2017 at 4:29

291 Answers 291

1
...
6
7
8 9 10
1
\$\begingroup\$

PowerShell, 5 bytes

$true

Output (including trailing linefeed):

True

Try it online!

answered Jul 8, 2017 at 19:59
\$\endgroup\$
0
1
\$\begingroup\$

Triangular, 9 bytes

9.(,%<>d]

Try it online!

Formats into this triangle:

 9 
 . ( 
 , % < 
 > d ] ÿ

Triangular auto-inserts ÿ wherever there is no source code to fill the smallest triangle.

Without control flow, the program looks like 9(%d]. Explanation:

  • 9 - push 9 to the stack
  • ( - open loop
  • % - print top of stack as integer
  • d - decrement top of stack
  • ] - jump back to ( if top of stack is truthy
answered Jun 15, 2017 at 4:54
\$\endgroup\$
1
\$\begingroup\$

Cubically, 2 bytes

%5

Try it online! Boring. Outputs 45. Also works with %4 (36), %3 (27), and %2 (18).

Cubically, 7 bytes

+5*66%6

Try it online! Outputs 4100625 by adding 45 to the notepad, then squaring it twice.

Cubically, 9 bytes

+5*5555%6

Try it online! Outputs 184528125 by adding 45 to the notepad, then multiplying it by 45 four times.

answered Jun 16, 2017 at 18:34
\$\endgroup\$
1
\$\begingroup\$

Python 3, 10 bytes

print(1e6)

Try it online!

answered Jul 15, 2017 at 14:40
\$\endgroup\$
1
\$\begingroup\$

Common Lisp REPL, 2 bytes

'a

returns a followed by a newline

answered Jul 22, 2017 at 7:15
\$\endgroup\$
1
\$\begingroup\$

Cubically, 2 bytes

%5

Try it online!

Prints the sum of all values on face 5. Face 5 is initialized to

555
555
555

so this prints

45

(Other valid answers: %2,%3,%4)

answered Aug 9, 2017 at 2:05
\$\endgroup\$
2
  • \$\begingroup\$ Note \$\endgroup\$ Commented Sep 12, 2017 at 3:51
  • 1
    \$\begingroup\$ @MDXF I really need to start reading existing answers more thoroughly instead of just assuming they haven't been solved in Cubically \$\endgroup\$ Commented Sep 12, 2017 at 13:04
1
\$\begingroup\$

Recursiva, 2 bytes

L(

Try it online!

It outputs 26.

L(
L - Length of
 ( - upper-case alphabet yield
answered Sep 12, 2017 at 3:49
\$\endgroup\$
1
\$\begingroup\$

Implicit, 1 byte

#

Pushes the length of the stack to the stack. Implicit output. Try it online!

1 byte alternatives

  • ß prints a space.
  • ±, $, +, -, *, /, _, and ^ all push 0 if the TIO input box is empty.
answered Sep 10, 2017 at 3:56
\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 3 bytes

?#Y

Output:

128

#Y is a constant used for checking the (Y) button, and has a value of 128.

answered Mar 3, 2018 at 16:20
\$\endgroup\$
1
  • \$\begingroup\$ I wonder if ? is acceptable since it prints a blank line. (Of course it's impossible to actually verify if the console writes a linefeed.) \$\endgroup\$ Commented Apr 20, 2018 at 3:47
1
\$\begingroup\$

x86 .COM opcode, 9 Bytes

0100 B409 MOV AH,09
0102 BAFF00 MOV DX,00FF
0105 CD21 INT 21
0107 C3 RET
0108 24 DB '$'
answered Mar 4, 2018 at 4:25
\$\endgroup\$
1
\$\begingroup\$

Flobnar, (削除) 9 (削除ここまで) 8 bytes

*<*@
9*<

Try it online!

Outputs 43046721, which is 98. This uses the -d flag to output in decimal. Thanks to Esolanging Fruit for this solution

answered Aug 13, 2018 at 6:30
\$\endgroup\$
1
  • \$\begingroup\$ 8 bytes \$\endgroup\$ Commented Aug 13, 2018 at 21:23
1
\$\begingroup\$

Z80Golf, (削除) 5 (削除ここまで) 3 bytes

00000000: 3e76 34 >v4

Try it online!

The output is vvv. Yay for ASCII-printable machine code!

Disassembly

start:
 ld a, 76ドル ; 3e 76
 inc (hl) ; 34

Uses the same concept as the 5-byte one: edit the running code on the fly, and abuse stack underflow.

The program initially loads 'v' to register a, and increments the value at the memory address (hl), which is 0000ドル where the code 3ドルe is located. Then the code becomes:

 ccf ; 3f ; Complement carry flag, effective no-op in this program
 halt ; 76
 inc (hl) ; 34

So the halt is uncovered right away. The stack underflow magic takes the next job; putchar's ret returns to 763ドルf, 0034ドル, and 0000ドル in the order, and three vs are printed in the process. Now pc is back at the start of the program. ccf is no-op, halt is executed, and the program terminates.


A variation, 4 bytes

00000000: 3e76 343b >v4;

Try it online!

The output is vvvv.

Disassembly

start:
 ld a, 76ドル ; 3e 76
 inc (hl) ; 34
 dec sp ; 3b

The added dec sp makes things slightly more convoluted; the stack is arranged so that putchar is run 4 times instead of 3. Without the instruction, the return addresses are 763ドルf - 3ドルb34 - 0000ドル; with it, the addresses are 3ドルe00 - 3476ドル - 003ドルb - 0000ドル.

Leaving this solution here, in case someone finds the "stack misalignment" technique useful.


Previous solution, 5 bytes

00000000: 2e0a 3e76 34 ..>v4

Try it online!

Disassembly

start:
 ld l, 0ドルa ; 2e 0a
 ld a, 76ドル ; 3e 76
 inc (hl) ; 34

The second instruction sets up the character to print, which is 'v'. The rest increases the value at the memory address 000ドルa.

The output is vvvvv. Too bad it's not in uppercase (and it's not six v's), otherwise I'd reference the game VVVVVV.

How it works

For no-input challenges, underflowing the stack into the code is a standard technique in Z80Golf. It is done by letting the PC flow beyond the end of the code, so that putchar at address 8000ドル is reached, a char is printed, and ret is executed.

  • When the code section is run the first time, the instruction at memory 000ドルa becomes ld bc, 0000ドル (opcode 01ドル 00ドル 00ドル). Pretty much no-op, since all registers are zeroed when the program starts. putchar is reached and v is printed once. Then it returns to 0ドルa2e.
  • putchar is run again, v is printed, and the next return address is 763ドルe.
  • Same thing again, return to 0034ドル.
  • Same thing again, finally return to 0000ドル, the start of the code.
  • The code is run again; the instruction at memory 000ドルa is now ld (bc), a (opcode 02ドル). a is 76ドル, so the value is written to memory 0000ドル. After putchar is reached this time, return to 0000ドル again, and PC meets the new instruction 76ドル which is... halt! The program ends.
answered Aug 13, 2018 at 5:30
\$\endgroup\$
1
\$\begingroup\$

MathGolf, 1 byte

!

Try it online!

For MathGolf, there is an implicit pop if nothing is on the stack and nothing is in the input. The operator will pop the default value for the type it's requesting, which is either 0, [] or "". That means that a lot of operators will pop implicit zeros from the empty stack, and transform them either into 0 or 1. There are 15 1-byte programs which satisfy the criteria of this challenge, most of them output 0. The rest output 1.

Output 0

*: 0
+: 0
,: 0
-: 0
.: 0
<: 0
>: 0
f: 0
i: 0
w: 0
x: 0

Output 1

!: 1
#: 1
): 1
=: 1
answered Dec 6, 2018 at 11:55
\$\endgroup\$
2
  • \$\begingroup\$ Doesn't ! output 1 as well by default? I remember using that in the How high can you count challenge. Also, your code contains *, but your TIO is . \$\endgroup\$ Commented Dec 6, 2018 at 12:04
  • \$\begingroup\$ You're absolutely correct. I created a script to search for all possible correct answers, ! must have gotten lost somewhere. My first thought was , but that's not printable ascii. I'll update the answer once I've looked for more possible correct answers. \$\endgroup\$ Commented Dec 6, 2018 at 12:06
1
\$\begingroup\$

PowerShell, 4 bytes

1..2

Try it online!

Output includes a trailing newline!

answered Dec 8, 2018 at 21:52
\$\endgroup\$
2
  • \$\begingroup\$ You could to try ,1 or +1. Output includes a trailing newline! \$\endgroup\$ Commented Dec 9, 2018 at 7:04
  • \$\begingroup\$ Thanks @mazzy, however I think that this method has already been used in this answer. \$\endgroup\$ Commented Dec 9, 2018 at 15:21
1
\$\begingroup\$

Husk, 2 bytes

s"

Try it online!

Prints "".

Husk, 2 bytes

_1

Try it online!

Prints -1.

answered Mar 28, 2019 at 21:14
\$\endgroup\$
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 23 bytes

	OUTPUT =DUPL(1,22)
END

Try it online!

Outputs 22 1s and then a newline.

answered May 3, 2019 at 19:39
\$\endgroup\$
1
\$\begingroup\$

Perl6 (削除) 12 (削除ここまで) 7 bytes

say |^6

Prints the number from 0-5 and a newline for 7 bytes. Suggested by Jo King.

Original

.say for ^7
answered Jul 29, 2019 at 9:18
\$\endgroup\$
0
1
\$\begingroup\$

Alchemist, 9 bytes

_->9Out__

Try it online!

Uses up the initial _ atom to output the number of _ atoms remaining (0) nine times.

answered Jul 30, 2019 at 17:52
\$\endgroup\$
1
\$\begingroup\$

brainfuck, 36 bytes

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

Try it online!

answered Aug 1, 2019 at 18:13
\$\endgroup\$
1
\$\begingroup\$

Keg, 2 bytes

Q.

Outputs 81, which is the ascii value of Q

Try it Online!

answered Aug 10, 2019 at 9:37
\$\endgroup\$
2
  • 2
    \$\begingroup\$ I thought ! would be shorter, but the implicit output has a trailing newline :( \$\endgroup\$ Commented Aug 10, 2019 at 9:55
  • 1
    \$\begingroup\$ It also has 3 trailing spaces for some reason \$\endgroup\$ Commented Aug 10, 2019 at 10:01
1
\$\begingroup\$

T-SQL, (削除) 21 (削除ここまで) 15 bytes

print space(15)

Try it online

Output:


 
answered May 17, 2017 at 21:49
\$\endgroup\$
1
  • \$\begingroup\$ Looks like a space is a valid output, so PRINT SPACE(15) would save you some bytes. \$\endgroup\$ Commented Aug 14, 2019 at 15:12
1
\$\begingroup\$

Keg, 2 bytes

2-byte answer:


Note that there is a 0x01 here. Try It Online!

answered Aug 14, 2019 at 15:02
\$\endgroup\$
0
1
\$\begingroup\$

AsciiDots, 8 bytes

.v.
(*$#

This starts with two dots, then duplicates them both, and then outputs all of their values. Might be golf able down to 6 bytes

Try it online!

answered Aug 21, 2019 at 12:10
\$\endgroup\$
1
\$\begingroup\$

Or, 5 bytes

 fals

This returns false (this should be a five-character constant) onto the stack, which can be used later in the program (or not really, none of the current known instructions in Or access non-top items).

Explanation

From the IRC log:

14:01 < fungot> mroman_: the command to push false is ' f'

Since fungot had not yet presented the full language, all that we know in the current interpreter is that extra instructions do nothing.

 f Push false onto the stack
 als All of those are recognized as NOPs in the current implementation.
answered Oct 17, 2019 at 13:43
\$\endgroup\$
2
  • \$\begingroup\$ Languages must have a known implementation to be valid here. \$\endgroup\$ Commented Oct 18, 2019 at 7:58
  • \$\begingroup\$ The known implementation is here. \$\endgroup\$ Commented Oct 18, 2019 at 10:19
1
\$\begingroup\$

Wren, (削除) 20 (削除ここまで)14 bytes

Fn.new{"1"*14}

Try it online!

Explanation

Fn.new{ } // Anonymous function
 "1"*14 // Returning the string "1" repeated 14 times
answered Dec 8, 2019 at 7:18
\$\endgroup\$
1
\$\begingroup\$

W, 2 bytes

1_

Explanation

1 % Push 1
 _ % Negate this number
% Therefore outputs -1
answered Dec 8, 2019 at 7:20
\$\endgroup\$
1
\$\begingroup\$

naz, 2 bytes

2o

Outputs 00.

Quite similar to my answer for Create output twice the length of the code.

answered Jan 21, 2020 at 5:49
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 6 bytes

say $~

Try it online!

From the Perl documentation:

$~ The name of the current report format for the currently selected output channel. The default format name is the same as the filehandle name. For example, the default format name for the STDOUT filehandle is just STDOUT .

answered Aug 8, 2020 at 23:46
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 1 byte

#

Prints a new line character

Try it online!

answered Jun 24, 2017 at 11:01
\$\endgroup\$
1
  • \$\begingroup\$ Is the ! necessary? If it was just # it would output a newline. \$\endgroup\$ Commented Sep 17, 2020 at 11:34
1
\$\begingroup\$

HTML (w3m -dump), 4 bytes

<s>

It outputs

[S:

Both source code and output contains a trilling new line.

answered Apr 1, 2021 at 7:40
\$\endgroup\$
1
...
6
7
8 9 10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.