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

\$\endgroup\$
22
  • 2
    \$\begingroup\$ Related. Related. \$\endgroup\$ Commented May 17, 2017 at 11:19
  • 22
    \$\begingroup\$ "Your code must not be a quine" but... but... it's tagged quine \$\endgroup\$
    – Okx
    Commented May 17, 2017 at 11:21
  • 4
    \$\begingroup\$ @Okx Because it's a generalised quine, i.e. the required output depends on the source code. \$\endgroup\$ Commented May 17, 2017 at 11:22
  • 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\$
    – Wheat Wizard
    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

288 Answers 288

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

Ohm v2, 1 byte

Try it online!

or

Try it online!

Ohm, 1 byte

º

Try it online!

or

°

Try it online!

Explanation

In Ohm if a component requires an input but no inputs are provided a 0 is implicitly pushed to the stack, so the output is 20 for the first program (in each version) and 100 for the second.

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

33, 1 byte

o

Prints 0, the default value of the accumulator.

i also works, printing a trailing newline.

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

8086/8088 machine code, 6 bytes

b8 21 21    mov ax, 2121         Load 0x2121 into AX.
ef ef ef    out [dx], ax (x3)    Output AX (2 bytes) to port [DX], 3 times.

Assumptions:

  • The output may be sent to I/O port 0.
  • DX is initialized with 0.

Joke answer:

ee    out [dx], al    Output AL (1 byte) to port [DX].

Assumptions:

  • The output may be sent to I/O port [DX], whatever that is.
  • AL is initialized with an ASCII character.
\$\endgroup\$
0
\$\begingroup\$

Python 3, 13 bytes

print('x'*13)

Try it online!

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

Zsh, 9 bytes

<<<$[9E7]

try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Should technically be 9E6 because of the trailing newline. \$\endgroup\$ Commented Aug 18, 2019 at 2:18
0
\$\begingroup\$

Python 3, 10 bytes

print(1e6)

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ you can save 1 byte by using Python 2: print 1e6 \$\endgroup\$
    – Beefster
    Commented Apr 30, 2019 at 17:37
  • \$\begingroup\$ Changing the language is not the point ;) \$\endgroup\$
    – movatica
    Commented Apr 30, 2019 at 17:56
  • \$\begingroup\$ This is also an exact duplicate of another answer. \$\endgroup\$
    – Beefster
    Commented Apr 30, 2019 at 17:57
  • \$\begingroup\$ That's possible. Tried to solve it without scrolling through 12 pages of answers first. \$\endgroup\$
    – movatica
    Commented Apr 30, 2019 at 17:58
  • 4
    \$\begingroup\$ You could do exit(1e5) to print to STDERR, saving 1 byte. \$\endgroup\$
    – maxb
    Commented Aug 15, 2019 at 9:33
0
\$\begingroup\$

PowerShell, 5 4 bytes

,0*2

Try it online!

-1 and fixing thanks to @ZaelinGoodman

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Technically outputs six characters; the five 'a' characters, and an implicit newline at the end Try it online!. One possible way to golf this down and maintain the spirit of your answer would be ,0*2; which outputs four characters (two zeroes, two newlines) Try it online! \$\endgroup\$ Commented Mar 4, 2021 at 19:27
0
\$\begingroup\$

Deadfish, 1 byte

o

Outputs 0. In Deadfish~, c outputs a NULL byte.

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

Scratch, 64 bytes

define
set[a v]to[
repeat[4
set[a v]to(join(a)([e ^ v]of[2
say(a

Uses scratchblocks syntax.

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

Pxem, 0 bytes (content) + 3 bytes (filename).

  • Filename: d.n
  • Content is empty.
  • Outputs 100 (if ascii-compatible environment).
\$\endgroup\$
0
\$\begingroup\$

Piet + ascii-piet, 20 bytes (14×2=28 codels)

eEeEUSABkKnNRTFEqKkk

Try Piet online!

Outputs 42949672964294967296.

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

Thunno, 1 byte

+

Attempt This Online!

Prints \$0\$. Also works in Thunno 2: Attempt This Online!

Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes

Z1

Attempt This Online!

Constant for \$10\$

Others include:

aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM, aN, aO, aP, aQ, aR

which are constants for \$10\$, \$15\$, \$20\$, ..., \$95\$.

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

2Col, 2 bytes

=0

Output:

0

Zero, with a trailing newline

Explanation:

    No input, therefore Cell initializes at 0
=0  Set Cell value to 0 and return Cell value
    Implicit: Print return value followed by a newline
\$\endgroup\$
0
\$\begingroup\$

Haskell, 16 bytes

main=print$2^48

Try it online!

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

Python REPL, 4 Bytes

9**4

\$9^4=6561\$

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

GNU calc, 2 bytes

~3

Outputs -4, the logical NOT of 3.

There's actually a ridiculous amount of quines in GNU calc (any plain number will do the trick), and a slightly fewer amount of non-quines that meet this challenge's requirements. This is a short non-quine.

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

Swift, 25 bytes

for i in 0...11{print(i)}

Prints the numbers 0 to 11 with trailing newlines.

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

Befalse (quirkster), 8 bytes

:::: 9.;

Try it!

Prints eight tab characters. 9. is the "loop body", and the leading :s increase the loop count as in the Fibonacci sequence (similar to Hello world trick). A space before 9 is necessary to ensure the last : executes the loop body twice in full.

\$\endgroup\$
1
6 7 8 9
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.