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\$ May 17, 2017 at 11:19
  • 22
    \$\begingroup\$ "Your code must not be a quine" but... but... it's tagged quine \$\endgroup\$
    – Okx
    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\$ 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
    May 17, 2017 at 22:37
  • 2
    \$\begingroup\$ @WheatWizard output by exit code is not a string, so it doesn't apply here. \$\endgroup\$ May 18, 2017 at 4:29

287 Answers 287

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

Knight, 2 bytes

O0

Try it online!

Prints 0, followed by a newline.

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

Pip, 1 byte

x

Outputs the empty string plus a trailing newline. Try it online!

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

JavaScript, 5 bytes

f=

x=>!1

console.log(f());

\$\endgroup\$
1
  • \$\begingroup\$ Cool, thank you, updated I think this follows the rules now \$\endgroup\$ Oct 19, 2021 at 14:36
1
\$\begingroup\$

Javascript REPL, 9 bytes

`${8**9}`

outputs the string

134217728

console.log(`${8**9}`)

Well, i like it

Javascript REPL, 8 Bytes

same approach 1 byte less

`${8e7}`

outputs the string

80000000

console.log(`${8e7}`)

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

SNOBOL4 (CSNOBOL4), 19 bytes

 output =99 ^ 9
end

Outputs:

913517247483640899

Try it online!

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

INTERCAL, 12 bytes

DOREADOUT#81

Outputs:

     
LXXXI

Try it online!

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

4, 39 bytes

3.6003960133602328000000002500100000194

Try it online!

How it works:

3.              Start of the program.
  6 00 39       Sets cell 00 to 39.
  6 01 33       Sets cell 01 to 33.
  6 02 32       Sets cell 02 to 32.
  8 00          While cell 00 is not zero:
    0 00 00 02  Sets cell 00 as the addition of cells 00 and 02.
    5 00        Gets the value of cell 00 and prints it as UNICODE character.
    1 00 00 01  Sets cell 00 as the subtraction of cells 00 and 01.
  9             End loop.
4               End of the program.

I avoided printing ASCII characters below 0x20, as the rules demanded. Otherwise, if one does not care for the nonprintable ASCII chars, it could be as simple as follows:

4, 27 bytes

3.60056 60101 800 500 1000001 9 4

Try it online!

Spaces kept for readability. Prints 0x56 to 0x00.

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

Backhand, 1 byte

h

Try it online!

Immediately halts, printing the top of the stack (if empty, 0) as a number.

Backhand, 4 bytes

v11H

Try it online!

Somewhat more interesting one which actually uses Backhand's execution nature. Prints four copies of ASCII 1; the 1s can be changed to any of 0-9a-f to print ASCII 0-15 characters.

v11H   initial step = 3
v    → reduce step size to 2
  1  → push 1
  1  ← bounce off and push 1
v      reduce step size to 1
 11  → push 1 twice
   H   halt, printing the entire stack as a string
\$\endgroup\$
1
  • 1
    \$\begingroup\$ There's also "H. for 3 bytes \$\endgroup\$
    – Jo King
    Nov 18, 2021 at 5:37
1
\$\begingroup\$

in floop, 2 bytes

;;

Try it online!

I seriously doubt it's possible to do anything more complex than this, as in floop's only output method is by halting.

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

Vyxal, 1 byte

×

Try it Online!

Apparently we don't have a Vyxal answer yet. Outputs *.

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

Ly, 1 byte

y

Try it online!

Pushes the size of the stack onto the stack, then exits. Entries on the stack are printed as numbers by default. Outputs 0.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Kinda feels like cheating, but it’s a perfectly valid answer! \$\endgroup\$ Jun 1, 2023 at 18:32
1
\$\begingroup\$

Desmoslang Assembly, 14 7 8 Bytes

[1...8OT

Old (14 Bytes):

EP+1M-14)14OJT
\$\endgroup\$
1
\$\begingroup\$

Rockstar, 8 bytes

Outputs 0.015625

say 1/64

Try it (code will need to be pasted in)

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

Python 3 (PyPy), 13 bytes

print('h'*13)

Try it online!

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

(,) 81 65 48 Chars or \$48\log_{256}(3)\approx\$ 9.51 Bytes

Thanks to @Leo for -17? chars!

(,,(),,(),,((),()()()()()()()(),,,(),,()()()()))

(Assuming by same number of bytes you mean same number of chars)
Tio

\$\endgroup\$
1
  • \$\begingroup\$ You can make it shorter by not using the N flag, since then each output will print 2 bytes (the number and a newline): inparencomma.pythonanywhere.com/… \$\endgroup\$
    – Leo
    Jul 6, 2023 at 3:26
1
\$\begingroup\$

Vyxal, 4 bytes

kSĖ 

There’s a trailing space.

Click the sus image below to Try It Online!™

Explanation

kSĖ­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏‏​⁡⁠⁡‌⁣​‎‏​⁢⁠⁢‌⁤​‎‏​⁢⁠⁡‌­ 
kS    # ‎⁡Push the character 'ඞ'.
  Ė   # ‎⁢Execute the top of the stack as Vyxal code.
      # Just a space
‎⁣
# ‎⁤When 'ඞ' is run as Vyxal code, it prints the string 'sus' with a newline.

💎 Created with the help of Luminespire at https://vyxal.github.io/Luminespire
\$\endgroup\$
0
1
\$\begingroup\$

///, 12 bytes

/a/bb/aaaaaa

Try it online!

Outputs bbbbbbbbbbbb. Explanation:

/a/bb/          Replace each a with bb
      aaaaaa    6 a's -> 12 b's (Implicit output)

Alternate program, also 12 bytes with same output:

/a/bbbbbb/aa

Try it online!

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

Vyxal, 5 bytes

`∞`∞₴

Output

\w+w\

Yes, I know. Very crazy.

Try it Online!

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

Ohm, 5 bytes

αvssL

Explanation

αvssL
αv    push 'aeiou'
  ss  convert to string two times (NOP)
    L print without newline
\$\endgroup\$
0
\$\begingroup\$

Pip, 4 bytes

L2P1

Try it online!

This prints 1\n1\n, at 4 bytes including the newlines.

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

Minimal-2D, 72 bytes

/D+++++++++L
 R/D          /LR/>>D     /LR
   R->++>+++<</UU   R->..</UU

Try it online!

Outputs 72 6s. This is BF in a 2D layout.

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

yup, 12 bytes

0e:::::{0##}

Try it online!

Pushes 6 1s, and, while there are 1 on the top of the stack, output a 0 followed by a 1.

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

Jellyfish, 2 bytes

p0

Try it online!

Prints 0 and a trailing linefeed.

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

Rexx 15 Bytes

say left("",15)

Try it here

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

Lua, 10 bytes

print(1e6)

Outputs:

1000000.0

Try it online!

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

Javascript, 10 bytes

alert(1e9)

Nodejs repl (maybe breaking rule)

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

Aceto, 9 1 byte

p

Prints the top value on the stack, an implicit 0.


Old solution (9 bytes):

p
¥×
19

Push a 1, push a 9. Multiply the (remaining) stack (by 9; → [1,1,1,1,1,1,1,1,1]).

Implode and print (prints 111111111).

The code is 9 bytes long in UTF-8 because ¥ and × take 2 bytes each.

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

Python 3 REPL, 2 bytes

1#

Prints 1 followed by a newline (\n)

\$\endgroup\$
1
  • \$\begingroup\$ 1; similarly works. \$\endgroup\$
    – user45941
    May 21, 2017 at 1:58
0
\$\begingroup\$

REXX 8 Bytes

say 9**8

Prints 43046721

\$\endgroup\$
2
  • \$\begingroup\$ This outputs a number but the challenge says it must be a string \$\endgroup\$ May 22, 2017 at 15:09
  • \$\begingroup\$ "You may only output bytes in the printable ASCII range (0x20 to 0x7E, inclusive)" Digits fall in that range \$\endgroup\$
    – theblitz
    May 22, 2017 at 20:18
0
\$\begingroup\$

Python 2, 13 bytes

Code:

print 10**12

Output:

1000000000000

Character Count: 13

\$\endgroup\$
13
  • \$\begingroup\$ What language is this? \$\endgroup\$ May 22, 2017 at 14:42
  • \$\begingroup\$ Edited. Python 2. Made it in 88 bytes. First timer in code-golf. \$\endgroup\$ May 22, 2017 at 14:44
  • \$\begingroup\$ Welcome to PPCG then! What are the imports for? \$\endgroup\$ May 22, 2017 at 14:45
  • \$\begingroup\$ Initially I thought I could use the randrange() function from the file "random". "import math" is for validating the 1E19 I placed later on. \$\endgroup\$ May 22, 2017 at 14:47
  • \$\begingroup\$ I can see there are better ways to get through, though. For example, I could do away with "import random", since I'm not using randrange() here. \$\endgroup\$ May 22, 2017 at 14:48
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.