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
...
6 7 8
9
10
0
\$\begingroup\$

Javascript, 10 bytes

alert(1e9)

Nodejs repl (maybe breaking rule)

1
answered May 18, 2017 at 17:54
\$\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.

answered May 18, 2017 at 15:07
\$\endgroup\$
0
\$\begingroup\$

Python 3 REPL, 2 bytes

1#

Prints 1 followed by a newline (\n)

answered May 20, 2017 at 9:26
\$\endgroup\$
1
  • \$\begingroup\$ 1; similarly works. \$\endgroup\$ Commented May 21, 2017 at 1:58
0
\$\begingroup\$

REXX 8 Bytes

say 9**8

Prints 43046721

answered May 20, 2017 at 22:14
\$\endgroup\$
2
  • \$\begingroup\$ This outputs a number but the challenge says it must be a string \$\endgroup\$ Commented 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\$ Commented May 22, 2017 at 20:18
0
\$\begingroup\$

Python 2, 13 bytes

Code:

print 10**12

Output:

1000000000000

Character Count: 13

answered May 22, 2017 at 14:37
\$\endgroup\$
13
  • \$\begingroup\$ What language is this? \$\endgroup\$ Commented May 22, 2017 at 14:42
  • \$\begingroup\$ Edited. Python 2. Made it in 88 bytes. First timer in code-golf. \$\endgroup\$ Commented May 22, 2017 at 14:44
  • \$\begingroup\$ Welcome to PPCG then! What are the imports for? \$\endgroup\$ Commented 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\$ Commented 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\$ Commented May 22, 2017 at 14:48
0
\$\begingroup\$

shortC on modern Linux

8 bytes

Araise(6

Output (with a newline):

Aborted 

10 bytes

Araise(7);}

Output (with a newline):

Bus error 

11 bytes

Araise(14);}

Output (with a newline):

Alarm clock 

11 btyes

Araise(15);

Output (with a newline):

Terminated 

12 bytes

Araise(16);}

Output (with a newline):

Stack fault 

13 bytes

Araise(29);} 

Output (with a newline):

I/O possible 

24 bytes

main(){raise(9*(1+1+1));

Output (with a newline):

Profiling timer expired 
answered May 23, 2017 at 4:11
\$\endgroup\$
0
\$\begingroup\$

Bean, 2 bytes

00000000: 253b %;

Explanation

Implicitly prints a 2 followed by a newline. I arbitrarily decided it should output the amount of bytes the program is, but this will work with many single characters in the printable range.

Try it online!

answered May 23, 2017 at 9:33
\$\endgroup\$
0
\$\begingroup\$

JavaScript, 32 bytes

Code: btoa(01234567891011121314151617)

Output: MS4yMzQ1Njc4OTEwMTExMjEzZSsyNA==

console.log(btoa(01234567891011121314151617))
console.log(btoa(01234567891011121314151617).length)
console.log("btoa(01234567891011121314151617)".length)

answered May 25, 2017 at 12:00
\$\endgroup\$
9
  • \$\begingroup\$ Invalid, without explicit output you need to say that it's in a repl \$\endgroup\$ Commented Jan 21, 2019 at 7:51
  • \$\begingroup\$ Not sure why you're bothering with a thread/post that's 2 years old, but the console.log is for the purpose of the code snippet preview only. Put those commands directly into the browser console and you'll see the correct result. \$\endgroup\$ Commented Jan 21, 2019 at 8:35
  • \$\begingroup\$ Well, yeah if you're using console.log it would be "Javascript (<browser name>)". As for the reason why I'm bothering, just because it's two years old doesn't mean it's allowed to be incorrect :P (plus, this question was active recently so I clicked on it and saw this) \$\endgroup\$ Commented Jan 21, 2019 at 9:28
  • \$\begingroup\$ Well, it's JavaScript, it's never going to win any Code Golf xD \$\endgroup\$ Commented Jan 21, 2019 at 10:22
  • \$\begingroup\$ Well, remember here you compete within the same language (well, kinda). The goal here is more to basically catalogue shortest solutions, I guess? \$\endgroup\$ Commented Jan 21, 2019 at 10:26
0
\$\begingroup\$

Check, 3 bytes (Non-competing)

>]p

Output:

[0]

> pushes 0, ] wraps it in an array, and p prints it.

answered Jun 18, 2017 at 5:07
\$\endgroup\$
0
\$\begingroup\$

j, 2 bytes

!4
 returns 24 (factorial 4)
\$\endgroup\$
0
\$\begingroup\$

Tcl/Tk, 18

pack [text .txt 1]

ouputs

unknown option "1"
answered Jul 21, 2017 at 23:34
\$\endgroup\$
0
\$\begingroup\$

j, 3 bytes

i.2

output...

0 1

(3 bytes including space)

\$\endgroup\$
1
  • \$\begingroup\$ If you can golf your answer down, please don't post a separate answer, just edit in the new solution. \$\endgroup\$ Commented Jul 22, 2017 at 7:36
0
\$\begingroup\$

ArnoldC, 309 bytes

Easy.

IT'S SHOWTIME
HEY CHRISTMAS TREE S
YOU SET US UP 1
HEY CHRISTMAS TREE T
YOU SET US UP 0
STICK AROUND S
GET TO THE CHOPPER T
HERE IS MY INVITATION T
GET UP 1
ENOUGH TALK
TALK TO THE HAND "SS"
GET TO THE CHOPPER S
HERE IS MY INVITATION 103
LET OFF SOME STEAM BENNET T
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

Note the double space between HERE IS MY INVITATION and 103 to have the good amount.

Golfable.

Try it online!

answered Jul 26, 2017 at 12:37
\$\endgroup\$
0
\$\begingroup\$

ROOP, 7 bytes

/rn/
ha

Try it online!

print IVXLCDM


The constant rn represents the string containing the Roman numerals.

The h operator terminates the program and prints all existing objects. The a operator is only to reach 7 bytes (there is no constant that has 6 characters).

answered Sep 5, 2017 at 20:34
\$\endgroup\$
0
\$\begingroup\$

J REPL, 2 bytes

+1

This outputs 1, then a newline.

MD XF
14.2k5 gold badges69 silver badges107 bronze badges
answered May 19, 2017 at 2:06
\$\endgroup\$
1
  • 2
    \$\begingroup\$ TIO doesn't execute the code in a REPL. You need echo or similar in a full program. \$\endgroup\$ Commented May 19, 2017 at 2:31
0
\$\begingroup\$

Google Sheets, (削除) 9 (削除ここまで) 4 Bytes

Google Sheets spreadsheet formula that takes no input and outputs a string of length 4 (output value := 1024 or 1000) to the spreadsheet cell that holds the formula.

=4^5

Or

=XE3 '' s.t. `x` is an integer in the range 1 To 9

--

Alternatively, 9 Bytes

Google Sheets spreadsheet formula that takes no input and outputs a string of length 9 to the spreadsheet cell that holds the formula.

=Rept(1,9
answered Jul 24, 2017 at 11:52
\$\endgroup\$
0
\$\begingroup\$

MY, 1 byte

0 is implicitly popped off of the stack, how nice!

Try it online!

answered Sep 18, 2017 at 11:29
\$\endgroup\$
0
\$\begingroup\$

GNU sed, 1 byte

Outputs a newline.

;

Try it online!

answered Dec 20, 2017 at 5:17
\$\endgroup\$
1
  • \$\begingroup\$ How do you test this? I created the source file printf ';' > sedscript and then specified it as a parameter sed ‐‐file=sedscript <&- but this prints zero bytes. \$\endgroup\$ Commented Mar 9, 2024 at 13:34
0
\$\begingroup\$

Aceto, 1 byte

p

Try it online!

Outputs 0

answered Dec 20, 2017 at 15:26
\$\endgroup\$
0
\$\begingroup\$

Pushy, 1 byte

_

Try it online!

Outputs a newline and nothing else.

This works not just with an underscore, but any character from: Qq'_"# (because these are all printing based commands, but there is nothing to print).

answered Dec 20, 2017 at 15:36
\$\endgroup\$
0
\$\begingroup\$

JsFuck for Firefox 31+ REPL, 604 bytes

[][([]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]
]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]])[!![]+!
![]+!![]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!
![]+[+[]]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]
])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!
![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+
[])[+[]]+([]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]
+[+[]]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]])[
!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+
[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]
]+(![]+[])[!![]+!![]]])[+!![]+[+[]]]+(!![]+[])[+!!
[]]](+(!![]+!![]+!![]+!![]+!![]+!![]+[+[]]+(+[])))
+![]
answered Mar 4, 2018 at 4:36
\$\endgroup\$
0
\$\begingroup\$

POSIX bc, 1 Byte

a

output:

0

Explanation: If you type a variable name it prints the value. Variables you haven't yet defined have the value zero.

answered Mar 30, 2018 at 20:01
\$\endgroup\$
1
  • \$\begingroup\$ The program needs to be two Bytes: a) printf 'a' | bc produces a syntax error. b) printf 'a\n' | bc | wc ‐c reports two bytes. The output string 0 is actually followed by one newline character and thus must be counted too. \$\endgroup\$ Commented Mar 9, 2024 at 13:28
0
\$\begingroup\$

Red / Rebol 5 bytes

1 > 2

Prints:

false
answered Jul 19, 2018 at 20:26
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Hello and welcome to PPCG. I am unfamiliar with Red / Rebol though this seems to only work in the REPL. If this is the case, please change the language name to something along the lines of Rebol REPL. To conform to our lax guidelines, you could also make your language name a header. \$\endgroup\$ Commented Jul 19, 2018 at 22:22
0
\$\begingroup\$

Attache, 8 bytes

!11|Echo

Try it online!

Other programs

9^8|Echo
!11|Echo
3|Echo//3
$A*10|Echo
Echo[$A*11]
$A*10|Print
Print[$A*11]
Echo//3 <|[]
Print//3 <|3
{_!_[0:1]}!Print
answered Jul 19, 2018 at 20:45
\$\endgroup\$
0
\$\begingroup\$
answered Apr 29, 2019 at 3:38
\$\endgroup\$
0
0
\$\begingroup\$

Python 3 only 3 bytes.

Type 01. in Python 3 interpreter and get 1.0 output.

answered Apr 29, 2019 at 16:21
\$\endgroup\$
1
  • 3
    \$\begingroup\$ This is a snippet for the REPL interpreter, not a full program or function. \$\endgroup\$ Commented Apr 29, 2019 at 16:48
0
\$\begingroup\$

TI-BASIC, 2 bytes

ᴇ1

Prints 10.

is this one-byte token.

answered Apr 29, 2019 at 19:23
\$\endgroup\$
0
\$\begingroup\$

Bash, 12 bytes

yes|head -n6

outputs 6 lines of ys (6 ys, 6 newlines)

answered Apr 30, 2019 at 17:44
\$\endgroup\$
0
\$\begingroup\$

Gol><>, 1 byte

h

Surprisingly easy, "h" pops off a number from the stack and prints that number, then ends the program. If there is no number then by default outputs 0.

Try it online!

answered Apr 30, 2019 at 17:47
\$\endgroup\$
0
\$\begingroup\$

C++ (gcc), (削除) 60 (削除ここまで) 58 bytes

#include<stdio.h>
int main(){for(int i=29;i--;)puts("x");}

Try it online!

answered Apr 30, 2019 at 17:28
\$\endgroup\$
4
  • 1
    \$\begingroup\$ This will output non-printable ascii. \$\endgroup\$ Commented Apr 30, 2019 at 17:46
  • \$\begingroup\$ Doh, missed the first rule, thanx! \$\endgroup\$ Commented Apr 30, 2019 at 17:57
  • \$\begingroup\$ You don't need the int part of the int main, do you? \$\endgroup\$ Commented May 3, 2019 at 5:06
  • \$\begingroup\$ Gray area... it just issues a compiler warning, but in fact it'd be invalid C++. \$\endgroup\$ Commented May 3, 2019 at 5:53
1
...
6 7 8
9
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.