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
aband 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 code-golf, 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>
-
2\$\begingroup\$ Related. Related. \$\endgroup\$Martin Ender– Martin Ender2017年05月17日 11:19:42 +00:00Commented May 17, 2017 at 11:19
-
1\$\begingroup\$ @Mr.Xcoder Yes, if you declare them as such. \$\endgroup\$Martin Ender– Martin Ender2017年05月17日 16:25:14 +00:00Commented 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\$Martin Ender– Martin Ender2017年05月17日 16:45:23 +00:00Commented 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\$Wheat Wizard– Wheat Wizard ♦2017年05月17日 22:37:40 +00:00Commented May 17, 2017 at 22:37
-
2\$\begingroup\$ @WheatWizard output by exit code is not a string, so it doesn't apply here. \$\endgroup\$Martin Ender– Martin Ender2017年05月18日 04:29:06 +00:00Commented May 18, 2017 at 4:29
291 Answers 291
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.
Swift, 36 bytes
print(String(repeating:" ",count:36))
JavaScript, 5 bytes
f=
x=>!1
console.log(f());
-
\$\begingroup\$ Cool, thank you, updated I think this follows the rules now \$\endgroup\$William Entriken– William Entriken2021年10月19日 14:36:28 +00:00Commented Oct 19, 2021 at 14:36
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}`)
4, 39 bytes
3.6003960133602328000000002500100000194
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
Spaces kept for readability. Prints 0x56 to 0x00.
Backhand, 1 byte
h
Immediately halts, printing the top of the stack (if empty, 0) as a number.
Backhand, 4 bytes
v11H
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
-
1\$\begingroup\$ There's also
"H.for 3 bytes \$\endgroup\$Jo King– Jo King2021年11月18日 05:37:59 +00:00Commented Nov 18, 2021 at 5:37
in floop, 2 bytes
;;
I seriously doubt it's possible to do anything more complex than this, as in floop's only output method is by halting.
Thunno, 1 byte
+
Prints \0ドル\$. Also works in Thunno 2: Attempt This Online!
Thunno, \$ 2 \log_{256}(96) \approx \$ 1.65 bytes
Z1
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ドル\$.
Ly, 1 byte
y
Pushes the size of the stack onto the stack, then exits. Entries on the stack are printed as numbers by default. Outputs 0.
-
1\$\begingroup\$ Kinda feels like cheating, but it’s a perfectly valid answer! \$\endgroup\$The Empty String Photographer– The Empty String Photographer2023年06月01日 18:32:08 +00:00Commented Jun 1, 2023 at 18:32
Desmoslang Assembly, (削除) 14 (削除ここまで) (削除) 7 (削除ここまで) 8 Bytes
[1...8OT
Old (14 Bytes):
EP+1M-14)14OJT
-
\$\begingroup\$ This works in regular python as well. \$\endgroup\$The Empty String Photographer– The Empty String Photographer2023年06月01日 18:42:57 +00:00Commented Jun 1, 2023 at 18:42
(,) (削除) 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
-
\$\begingroup\$ You can make it shorter by not using the
Nflag, since then each output will print 2 bytes (the number and a newline): inparencomma.pythonanywhere.com/… \$\endgroup\$Leo– Leo2023年07月06日 03:26:03 +00:00Commented Jul 6, 2023 at 3:26
Vyxal, 4 bytes
kSĖ
There’s a trailing space.
Click the sus image below to Try It Online!TM
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
///, 12 bytes
/a/bb/aaaaaa
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
Befalse (quirkster), 8 bytes
:::: 9.;
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.
Bespoke, 16 bytes
Bespoke program.
Prints Stack underflow. to STDERR.
Alternate version, 47 bytes
"Hey, so can I do some modified way?" stated I.
Prints 31^31, which is 47 digits long.
Ohm, 5 bytes
αvssL
Explanation
αvssL
αv push 'aeiou'
ss convert to string two times (NOP)
L print without newline
Minimal-2D, 72 bytes
/D+++++++++L
R/D /LR/>>D /LR
R->++>+++<</UU R->..</UU
Outputs 72 6s. This is BF in a 2D layout.
yup, 12 bytes
0e:::::{0##}
Pushes 6 1s, and, while there are 1 on the top of the stack, output a 0 followed by a 1.