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 2 3
4
5
...
10
2
\$\begingroup\$

JavaScript (ES6), 17 bytes

Edit: I overlooked the rules. This is now returning a string, but is much longer than initially intended.

Returns "Infinity,Infinity".

let f =
_=>`${[1/0,1/0]}`
console.log(f())

answered May 17, 2017 at 11:35
\$\endgroup\$
0
2
\$\begingroup\$

C#, (削除) 57 (削除ここまで) (削除) 49 (削除ここまで) (削除) 47 (削除ここまで) 44 bytes

()=>{for(int i=0;i<44;i++)Console.Write(7);}

-8 bytes thanks to Martin

Not 100% on whether lambdas like this are accepted answers, but my previous submission in this format was accepted just fine, so I'm gunna go with it.

Same as the java answer, but better because it's not Java

answered May 17, 2017 at 11:50
\$\endgroup\$
0
2
\$\begingroup\$

Deadfish, 1 byte

o

Outputs the accumulator, which is 0 before any action takes place.

note: deadfish prints the accumulator as a number, not as a character code, so the output is "0" (0x48)

answered May 17, 2017 at 12:26
\$\endgroup\$
2
\$\begingroup\$

QBIC, (削除) 8 (削除ここまで) 2 bytes

?z

Prints 10, to which z is auto-initialised.


Original (削除) brainfart (削除ここまで) answer

?A+@1234

Explanation:

? PRINT
A+ A$ (which is undefined, but hold on!), plus
@1234 The string literal 1234, which we now call A$

Outputs 12341234, which is also 8 bytes. We save a byte by putting the string lit at EOF, because we now don't need to use the delimiter. The definition of the literal is moved to the top of the QBasic code by the interpreter, ensuring it existst at the moment of the first call to A$.

answered May 17, 2017 at 11:49
\$\endgroup\$
2
\$\begingroup\$

SQLite, 32 bytes

.width 31
.mode column
SELECT"";

Try it online!

Outputs 31 spaces and a newline.

answered May 17, 2017 at 14:01
\$\endgroup\$
0
2
\$\begingroup\$

Brain-Flak, 12 bytes

(((([()]))))

Try it online!

This prints

-1
-1
-1
-1
answered May 17, 2017 at 16:23
\$\endgroup\$
3
  • \$\begingroup\$ This seems to be 11 bytes of output, not 12. \$\endgroup\$ Commented May 17, 2017 at 16:34
  • \$\begingroup\$ @DJMcMayhem You're right, fixed \$\endgroup\$ Commented May 17, 2017 at 16:39
  • \$\begingroup\$ It's to bad -v print Brain-Flak Ruby Interpreter v1.4.2 instead of just v1.4.2. \$\endgroup\$ Commented May 17, 2017 at 23:30
2
\$\begingroup\$

Stacked, 9 bytes

$put:+put

Try it online!

Outputs [put put]. $put pushes a function literal to the stack, : duplicates it, + concats the two functions, and put outputs the representation of the top of the stack.

answered May 17, 2017 at 19:08
\$\endgroup\$
2
\$\begingroup\$

Haskell, 16 bytes

main=print[0..6]

Try it online! Output:

[0,1,2,3,4,5,6]

(Note the trailing newline.)

answered May 17, 2017 at 19:37
\$\endgroup\$
2
\$\begingroup\$

MSM, 8 bytes

'.;;.;.;

Output:

........

MSM operates on its own source and takes commands from the left and treats the right as a stack. Stack trace:

' . ; ; . ; . ; # ' pushes the next char on the stack
 ; ; . ; . ; . # ; is dup
 ; . ; . ; . . # dup again
 . ; . ; . . . # . is concat
 ; . ; . .. # dup 
 . ; . .. .. # concat
 ; . .... # dup
 . .... .... # concat
 ........ # MSM stops if there's only one element in the stack
answered May 17, 2017 at 19:55
\$\endgroup\$
2
\$\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.

answered May 17, 2017 at 20:35
\$\endgroup\$
2
\$\begingroup\$

Python 2, 11 bytes

print 4**16

Beep boop.

answered May 17, 2017 at 11:30
\$\endgroup\$
2
  • 1
    \$\begingroup\$ You can do 8**9 for 10 bytes. \$\endgroup\$ Commented May 17, 2017 at 12:14
  • 1
    \$\begingroup\$ @Pietu1998 I was about to do 9**9, but @DeadPossum ninja'd me, so I'd rather keep this... \$\endgroup\$ Commented May 17, 2017 at 12:16
2
\$\begingroup\$

Forth, 6 bytes

1e3 f.

Try it online

Output:

1000. 

Note the trailing space.

answered May 17, 2017 at 21:25
\$\endgroup\$
2
\$\begingroup\$

Python 3 REPL, 3 bytes

1e0

Prints 1.0.

If trailing newline counts,

5*2

Prints 10, then a trailing newline.

answered May 18, 2017 at 0:21
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Yes, the trailing linefeed counts. \$\endgroup\$ Commented May 18, 2017 at 4:36
2
\$\begingroup\$

TacO, 1 byte

@

Outputs a single newline.

Taco's default behaviour is to print out a newline, for some reason. But, the code needs an entry point, @, to work. So this works.

Try it online!

answered May 18, 2017 at 2:43
\$\endgroup\$
2
\$\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

Beta Decay
23.6k9 gold badges74 silver badges169 bronze badges
answered May 17, 2017 at 13:36
\$\endgroup\$
1
  • 2
    \$\begingroup\$ printf %11s outputs exactly 11 spaces \$\endgroup\$ Commented May 17, 2017 at 15:54
2
\$\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.

answered May 18, 2017 at 19:54
\$\endgroup\$
2
\$\begingroup\$

Japt, 1 byte

Outputs a string containing a single ".

Q

Try it online


Or this will output a string containing a single \n.

R

Try it online

answered May 18, 2017 at 16:14
\$\endgroup\$
4
  • \$\begingroup\$ Heh, nice. S will work too, or T, or U, or a, or f, or... there are probably 40 or so options that print 0 or 1. \$\endgroup\$ Commented May 19, 2017 at 0:46
  • \$\begingroup\$ @ETHproductions, T, U, a, f, etc. wouldn't be valid as string output is required. s works, though. \$\endgroup\$ Commented May 19, 2017 at 7:44
  • \$\begingroup\$ Only functions are required to return strings. The output of any program is considered a string by default, since there's no way to tell between outputting "123" vs. 123 (both just show up as 123) \$\endgroup\$ Commented May 19, 2017 at 12:02
  • \$\begingroup\$ Unless, in the case of Japt, you use the -Q flag ;) But that's good to know, thanks @ETHproductions. \$\endgroup\$ Commented May 19, 2017 at 12:04
2
\$\begingroup\$

7, 3 characters, 1 byte

Seen as individual characters:

723

Or as a hex dump, proving that it runs from a file that's one byte long:

00000000: e9 .

Try it online!

Outputs the characters 23 in 7's encoding. This also happens to be a single byte long, and a printable ASCII byte at that:

00000000: 4f O

Explanation

This is a literal that pushes two stack elements: an empty stack element (7 separates stack elements), and 23, 7's print statement. When the end of the program is reached, the top stack element is copied and evalled, meaning that an attempt is made to print 23; because this contains characters that don't exist in 7's encoding (the active versions of the 2 and 3 commands, shown in bold in the explanation), the printed value gets escaped (into 723), and the 7 is interpreted as a request to format the output in the same encoding as the input, with the 23 getting printed.

It can be observed that the leading 7 on the program is entirely pointless, except to make the output and input distinct.

answered May 19, 2017 at 2:19
\$\endgroup\$
2
\$\begingroup\$

Carrot, 4 bytes

.^*3

Prints .... (4 .s).

Try it online!

Explanation

.^ Sets the stack-string to "."
 *3 Append three duplicates of the stack-string to itself
 Implicit output
answered May 21, 2017 at 12:46
\$\endgroup\$
2
\$\begingroup\$

Ruby, 16 bytes

puts (1..8).to_a

returns

1
2
3
4
5
6
7
8

Can I use this to enter challenge?
Try it Online!

answered May 23, 2017 at 8:56
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Looks good to me. Welcome to PPCG! :) \$\endgroup\$ Commented May 23, 2017 at 8:57
  • \$\begingroup\$ p (1..4).to_a should work, for 13 bytes. \$\endgroup\$ Commented May 23, 2017 at 17:50
  • \$\begingroup\$ @Dennis and codegolf.stackexchange.com/a/121108/6691 is even shorter and already posted, so what's the point of that comment? \$\endgroup\$ Commented Jun 13, 2017 at 20:09
  • \$\begingroup\$ @b_jonas Just because someone achieved a better score doesn't mean you can't try to get the most of your approach. \$\endgroup\$ Commented Jun 13, 2017 at 20:15
2
\$\begingroup\$

ZX Spectrum BASIC, 1 byte

PRINT

(which is 1 byte) prints a single newline.

answered May 23, 2017 at 12:07
\$\endgroup\$
1
  • \$\begingroup\$ I think Apple][ integer Basic does a similar thing with ? for PRINT \$\endgroup\$ Commented Aug 15, 2019 at 2:02
2
\$\begingroup\$

dc (bash command line under Linux), 9 bytes

(inc newlines on both the math expression and the answer)

2 24 ^ p

Prints:

16777216

I wanted to make sure RPN wasn't forgotten about :)

answered May 23, 2017 at 17:48
\$\endgroup\$
6
  • \$\begingroup\$ Welcome to PPCG! You're a little bit outgolfed already. \$\endgroup\$ Commented May 23, 2017 at 17:53
  • \$\begingroup\$ @ØrjanJohansen, hehe yes I don't mind, to be honest I just wanted to play along. The day that P8x32A Assembly language is a valid language around here I'll whup everyone :D \$\endgroup\$ Commented May 23, 2017 at 17:55
  • \$\begingroup\$ You're free to use any language you want (as long as there's a working implementation), including P8x32A assembly. \$\endgroup\$ Commented May 23, 2017 at 17:58
  • \$\begingroup\$ @Dennis, define "working". I doubt many PCG frequenters would feel like grabbing a soldering iron and building a circuit to prove that the code works :) \$\endgroup\$ Commented May 23, 2017 at 18:00
  • 1
    \$\begingroup\$ So basically it needs an emulator. \$\endgroup\$ Commented May 23, 2017 at 18:03
2
\$\begingroup\$

Microscript, 1 byte

E

Prints 100=1. e will also work, printing 20=1.

answered May 23, 2017 at 19:09
\$\endgroup\$
2
\$\begingroup\$

Forth (gforth), 4 bytes

.S \

Prints <0> (that's <, 0, >, and space). Stack must be empty (for example if gforth was just started)

How it works: .S prints the stack depth enclosed in brackets and then the stack contents seperated with a space. \ is the beginning of a comment, it does nothing.

Forth (gforth), 8 bytes

8 SPACES

Well, it prints 8 spaces. Not much to see here.

answered May 24, 2017 at 11:39
\$\endgroup\$
2
\$\begingroup\$

SmileBASIC 3, 3 bytes

?@A

Prints the string @A, plus a trailing newline, so output is 3 bytes.

answered May 25, 2017 at 12:43
\$\endgroup\$
2
\$\begingroup\$

MarioLANG, 1 byte

:

Output the numeric value from current memory cell, which is 0

answered May 25, 2017 at 19:37
\$\endgroup\$
2
\$\begingroup\$

TI-Basic, 7 bytes

(Ab)using the fact that Done is displayed when nothing is evaluated on the last line. Lowercase letters are two bytes each in TI-Basic.

Repeat 1337:End
answered May 27, 2017 at 14:13
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I wouldn't count printed lowercase letters as two bytes. Lowercase letter tokens take two bytes to store, but I think the calculator doesn't store the tokens when it prints the letters. \$\endgroup\$ Commented Jul 11, 2017 at 1:36
  • 1
    \$\begingroup\$ @lirtosiast You could always have something like Repeat 1:End for 4 bytes of course. \$\endgroup\$ Commented Jul 11, 2017 at 2:21
  • 1
    \$\begingroup\$ Yes, that would be better \$\endgroup\$ Commented Jul 11, 2017 at 16:19
2
\$\begingroup\$

JavaScript, 35 bytes

Source:

console.log(([]+[])["constructor"])

Output:

function String() { [native code] }
Wheat Wizard
103k23 gold badges299 silver badges697 bronze badges
answered Jun 2, 2017 at 15:32
\$\endgroup\$
2
\$\begingroup\$

HQ9+, 13 bytes

haaaaaaaaaaaa

Prints:

Hello, world!

The instruction "h" in HQ9+ will print "Hello, world!" and any instruction that is not "h" "q" "9" or "+" will be ignored.

You might want to know why this language exists, and why I'm answering this question with it.

Why not?

answered Jul 9, 2017 at 1:41
\$\endgroup\$
2
\$\begingroup\$

Python 3 REPL, 11 bytes

str(...)[:]

Try it online! The header and the footer emulate a REPL.

This prints:

'Ellipsis'

answered Aug 9, 2017 at 1:25
\$\endgroup\$
1 2 3
4
5
...
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.