102
\$\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\$
19
  • 2
    \$\begingroup\$ Related. Related. \$\endgroup\$ – Martin Ender May 17 '17 at 11:19
  • 21
    \$\begingroup\$ "Your code must not be a quine" but... but... it's tagged quine \$\endgroup\$ – Okx May 17 '17 at 11:21
  • 4
    \$\begingroup\$ @Okx Because it's a generalised quine, i.e. the required output depends on the source code. \$\endgroup\$ – Martin Ender May 17 '17 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 '17 at 22:37
  • 2
    \$\begingroup\$ @WheatWizard output by exit code is not a string, so it doesn't apply here. \$\endgroup\$ – Martin Ender May 18 '17 at 4:29

252 Answers 252

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

MAWP, 13 bytes

43W2M[84W;1A]

Prints 14 space characters.

Try it!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice, but here codegolf.stackexchange.com/a/209253/92080 is a 1 byter :) \$\endgroup\$ – Dion Aug 8 '20 at 10:45
  • \$\begingroup\$ I thought the . was required for output. Anyway, the question asks for an ASCII character so I made this. \$\endgroup\$ – Razetime Aug 8 '20 at 10:50
  • 3
    \$\begingroup\$ Well, to be fair the output not appearing without a . was a bug that is now fixed, my bad. And 1 is also an ASCII character (49) \$\endgroup\$ – Dion Aug 8 '20 at 14:25
2
\$\begingroup\$

05AB1E, 1 byte

,

Try it online!

,  # output top of stack (nothing) with trailing newline
\$\endgroup\$
2
\$\begingroup\$

Bash, 6 bytes

(arch)

Try it online!

The architecture needs to be x86_64

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

Rust, 30 28 bytes

fn main(){print!("{:28}",0)}

Try it online!

Prints zero, padded with enough spaces so that it is 28 bytes long.

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

MAWP, 1 bytes

:

Try it!

Prints the 1 thats already on stack

\$\endgroup\$
4
  • \$\begingroup\$ A fun but longer solution is M:. \$\endgroup\$ – Jo King Aug 8 '20 at 12:54
  • \$\begingroup\$ @JoKing I'm a bit confused. The link you are giving points a completely different submission, while M:. would result in an error: M needs two numbers off the stack whereas the starting stack is only [1]. Could you please clarify what you meant? \$\endgroup\$ – Dion Aug 8 '20 at 14:23
  • \$\begingroup\$ Oh, weird, the generate link didn't work the way I expected it to. I meant this, which prints NaN \$\endgroup\$ – Jo King Aug 8 '20 at 14:40
  • \$\begingroup\$ @JoKing that is actually a really smart solution imo, feel free to post it as another solution \$\endgroup\$ – Dion Aug 8 '20 at 18:36
2
+50
\$\begingroup\$

Red, 32 bytes

i: 1 until[prin i: i + 1 i > 20]

Try it online!

Sets i to 1, then increments i and prints it without trailing newlines until i is greater than 20. This prints the numbers [2..21] without delimiters, an output 32 characters long.

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

PHP, 17 bytes

<?php echo 9**17;

Because I wanted to beat Mayube's answer ;)

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ Touche. I'll get you next time ;) \$\endgroup\$ – Skidsdev May 17 '17 at 11:38
  • \$\begingroup\$ Looks like I got you, kind of :D \$\endgroup\$ – Skidsdev May 17 '17 at 12:15
  • 1
    \$\begingroup\$ same way golfed <?=9**8; \$\endgroup\$ – Jörg Hülsermann May 17 '17 at 13:09
  • \$\begingroup\$ Sorry can't beat Mayube/Jörg's byte count but at least I can give a good and creative tip: <?=1/64;. \$\endgroup\$ – Christoph May 17 '17 at 13:10
1
\$\begingroup\$

Go, 60 bytes

I don't know if this is hard in Go or if I'm failing to see something obvious.

import(."fmt"
."strings")
func main(){Print(Repeat("a",60))}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Can you do something like 1e30 or 10^49? \$\endgroup\$ – CalculatorFeline May 17 '17 at 19:03
  • \$\begingroup\$ @CalculatorFeline 1e30 would print 1e+37 and 10^49 would print 37 (due to bitwise operation). \$\endgroup\$ – totallyhuman May 22 '17 at 20:24
1
\$\begingroup\$

brainfuck, 33 bytes

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

Try it online!

Output:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I could do it in 32 bytes but I decided this is better.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Then do it in 32 bytes. \$\endgroup\$ – CalculatorFeline May 17 '17 at 19:04
  • \$\begingroup\$ You should do it in 32 bytes or else it isn't a serious competing entry. \$\endgroup\$ – Erik the Outgolfer May 24 '17 at 13:42
1
\$\begingroup\$

Braingolf, 1 byte

l

Try it online!

Prints 0 (the current length of the stack)

Braingolf, 2 byte

4*

Prints 16. 4 can be replaced by any number n where 3 < n < 10

Explanation:

4*
4   Pushes 4 to the stack
 *  Monadic multiplication, squares the last item on the stack
    Implicit output of the last item on the stack
\$\endgroup\$
3
  • \$\begingroup\$ @LuisMendo That's the correct link. TIO doesn't have Braingolf yet, but the interpreter is written in Python3, which TIO does have. The code is the 2nd argument. \$\endgroup\$ – Skidsdev May 17 '17 at 11:36
  • 1
    \$\begingroup\$ Don't you think you should explain that in your answer then? \$\endgroup\$ – Luis Mendo May 17 '17 at 11:38
  • \$\begingroup\$ Doesn't the first solution print a trailing newline? \$\endgroup\$ – totallyhuman Jun 3 '17 at 12:01
1
\$\begingroup\$

brainfuck, 30 bytes

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

Outputs 30 #s.

Try it online!

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

Brain-Flak, 32 bytes

(((()()()){}){}()){(({})[()])}()

Try it online!

Prints:

0
1
2
3
...
13

Explanation:

# Push 13
(((()()()){}){}())

# While TOS != 0
{

   # Push TOS, TOS - 1
   (({})[()])

# End While and pad with 2 bytes
}()
\$\endgroup\$
1
1
\$\begingroup\$

Perl 6, 4 bytes

{?1}

Try it

Returns True

Explanation

&prefix:« ? » is a Bool conversion operator

{ and } can be used to create a bare block lambda.

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

Actually, 1 byte

ε

Try it online!

Prints the empty string (and a trailing newline).

\$\endgroup\$
1
  • \$\begingroup\$ " would also work, as would . \$\endgroup\$ – user45941 May 18 '17 at 3:03
1
\$\begingroup\$

S.I.L.O.S, 28 bytes

i=28
lblb
i-1
print a
if i b

Try it online!

Output:

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

brainbool, 1 byte

.

Try it online!

brainbool is like brainfuck, except cells can only contain 0 or 1. Outputting in brainbool always produces an ASCII 0 or 1. All cells start out as 0, so . will output 0.

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

Forth, 6 bytes

1e3 f.

Try it online

Output:

1000. 

Note the trailing space.

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

WinDBG, 7 bytes

??1;$$$

Outputs:

int 0n1

How it works:

??1;        Evaluate (and implicit print) 1 as a C++ expression
    $$$     Comment, ignored
\$\endgroup\$
1
\$\begingroup\$

Java, 70 bytes

interface M{static void main(String[]a){System.out.format("%70d",0);}}

Prints 69 spaces and a zero.

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

Scala, 9 bytes

()=>"x"*9

This is a function which returns "xxxxxxxxx".

Try it online

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

Bash, 11 bytes

printf %11s

prints:

"           "

(without the quotes)

If the newline counts, then printf "%10s" will print 10 characters plus the newline.

I did consider echo $0 (7) which works when saved with a filename 7 characters long, but I think that falls under the common set of unaccepted answers

\$\endgroup\$
1
  • 2
    \$\begingroup\$ printf %11s outputs exactly 11 spaces \$\endgroup\$ – Digital Trauma May 17 '17 at 15:54
1
\$\begingroup\$

Excel, 13 (12/11) bytes

=TEXT(9^13,0)

Genetrate a number, convert to text, simple!

Alternatively: =1=1 evaluates to TRUE (4bytes)

TRUE is boolean not text

Update

Very debateably for 12 and 11 bytes respectively

=TEXT(9^12,0

Leaving off the close bracket evaluates without a fuss

=REPT("a,11

Leaving out a bracket and " still evaluates although you get a "did you mean...?" prompt correcting the formula. I think the 1st is probably fine, the 2nd probably isn't.

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

VBA Immediate Window, 9, 2 bytes

?,

Prints a tab followed by a newline according to this answer in meta

Old answer

?space(6)

Entered in the immediate window, space(n) repeats the space character n times, ? is short for Print & Debug. is implicitly prepended in the immediate window. Printing also gives a space after the function and 2 newlines so only 6 spaces needed

\$\endgroup\$
1
  • \$\begingroup\$ Nice job! Golfing down to 22% of original code in one step is pretty impressive. \$\endgroup\$ – MD XF May 18 '17 at 22:53
1
\$\begingroup\$

Brian & Chuck, 9 bytes

?{-?
	.{?

Try it online!

Prints ?????????.

The first character on the second line is a tab.

Explanation

The tab's code point is 9 and it's just used as a counter to loop the correct number of times.

The program starts by immediately switching to Chuck with ?. The . prints that ?, { currently does nothing and ? switches back to Brian.

We now start the main loop which runs 8 times. { moves the tape head on Chuck back to the first cell, i.e. the tab. - decrements this counter. Once the counter hits zero, ? does nothing and the program ends. But until that happens it switches control back to Chuck. Then . prints another ?, { resets the tape head on Brian to the beginning and ? hands control back to him. This way, the two instances alternate between decrementing the counter on Chuck and printing a ? on Brian.

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

R, 8 9 bytes

cat(8^8)

Prints 16777216 to stdout. cat(F) would have been better, but there isn't a trailing newline on the output. Thanks to @user2390246 for a byte.

Try it online!

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

braingasm, 1 byte

Prints 0 (without newline):

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

shortC, 15 10 8 7 6 bytes

AR"%6d

Output: A random integer x with y spaces before it. y = strlen(itoa(x))

Directly stolen from Doorknob.

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

PARI/GP, 2 bytes

4!

Prints 24. (This is using the REPL, which is essentially the only way the language is used.)

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

Frink, 9, 11, 10 bytes

print[13!]

Outputs:

6227020800

Such a ... boring solution, sigh.
*no trailing newlines.
*Although Frink parses unicode exponents {+- 0-9}, print[9⁹] is 11 bytes, not 9.
Frink has a large data file of constants, but I haven't yet found a < 4 char one that outputs < 11 bytes. (constants have units, and frink is very verbose by default)

\$\endgroup\$
2
  • \$\begingroup\$ That seems to be 3 bytes. \$\endgroup\$ – Ørjan Johansen May 19 '17 at 1:20
  • \$\begingroup\$ grr, of course it is. So silly of me to trust the byte size of the native-editors saved file without reloading it to check for corruption. (I did check if it appended a newline) \$\endgroup\$ – maybeso May 20 '17 at 22:31
1
\$\begingroup\$

Batch - 6 Bytes

xcopy^

Not sure if this counts, but the typing this in cmd will give the output:

More? 

(With a trailing space)

\$\endgroup\$
1
1
3 4
5
6 7
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.