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
...
4 5
6
7 8
...
10
1
\$\begingroup\$

brainfuck, 33 bytes

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

Try it online!

Output:

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

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

answered May 17, 2017 at 12:10
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Then do it in 32 bytes. \$\endgroup\$ Commented May 17, 2017 at 19:04
  • \$\begingroup\$ You should do it in 32 bytes or else it isn't a serious competing entry. \$\endgroup\$ Commented May 24, 2017 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
answered May 17, 2017 at 11:24
\$\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\$ Commented May 17, 2017 at 11:36
  • 1
    \$\begingroup\$ Don't you think you should explain that in your answer then? \$\endgroup\$ Commented May 17, 2017 at 11:38
  • \$\begingroup\$ Doesn't the first solution print a trailing newline? \$\endgroup\$ Commented Jun 3, 2017 at 12:01
1
\$\begingroup\$

brainfuck, 30 bytes

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

Outputs 30 #s.

Try it online!

answered May 17, 2017 at 13:06
\$\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
}()
answered May 17, 2017 at 13:31
\$\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.

answered May 17, 2017 at 13:42
\$\endgroup\$
1
  • \$\begingroup\$ That returns the boolean value True, not the string "True". If you run it at the REPL it does display as "True", but does the trailing newline count when added by the REPL? I think you can fix both of those by doing {~?1}, which both adds a byte to account for the newline and explicitly stringifies the result. \$\endgroup\$ Commented Mar 15, 2023 at 13:22
1
\$\begingroup\$

Actually, 1 byte

ε

Try it online!

Prints the empty string (and a trailing newline).

answered May 17, 2017 at 14:32
\$\endgroup\$
1
  • \$\begingroup\$ " would also work, as would しかく. \$\endgroup\$ Commented May 18, 2017 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
answered May 17, 2017 at 14:35
\$\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
answered May 17, 2017 at 22:40
\$\endgroup\$
1
\$\begingroup\$

Java, 70 bytes

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

Prints 69 spaces and a zero.

answered May 18, 2017 at 4:54
\$\endgroup\$
1
\$\begingroup\$

Scala, 9 bytes

()=>"x"*9

This is a function which returns "xxxxxxxxx".

Try it online

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

answered May 17, 2017 at 16:03
\$\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

answered May 17, 2017 at 15:29
\$\endgroup\$
1
  • \$\begingroup\$ Nice job! Golfing down to 22% of original code in one step is pretty impressive. \$\endgroup\$ Commented May 18, 2017 at 22:53
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!

answered May 18, 2017 at 19:22
\$\endgroup\$
0
1
\$\begingroup\$

braingasm, 1 byte

Prints 0 (without newline):

:
answered May 19, 2017 at 17:03
\$\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.

answered May 18, 2017 at 2:11
\$\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.)

answered May 19, 2017 at 18:54
\$\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[99] 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)

answered May 18, 2017 at 21:13
\$\endgroup\$
2
  • \$\begingroup\$ That 9 seems to be 3 bytes. \$\endgroup\$ Commented May 19, 2017 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\$ Commented May 20, 2017 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)

answered May 22, 2017 at 18:35
\$\endgroup\$
1
1
\$\begingroup\$

Bash + coreutils, 5 bytes

id -u

Technically depends on the user ID, but the default user has id 1000 on all major distros, and unless you set up 9,000+ additional users, all others will also have a four-digit id.

Finally, this works on TIO, so I'd argue it meets our must work in one implementation rule.

Try it online!

answered May 23, 2017 at 7:02
\$\endgroup\$
1
\$\begingroup\$

Pyke, 1 byte

k

Try it online!

Pushes the empty string and then prints it with a newline

answered May 23, 2017 at 9:13
\$\endgroup\$
1
\$\begingroup\$

Klein, 3 + 3 = 6 bytes (non-competing)

Non-competing because " was added after this challenge. +3 bytes for the 000 topology flag.

"@.

Try it online!

Prints 64 46 and a trailing linefeed.

Explanation

With the 000 topology the source code just wraps around like in many other fungeoids.

"@." Push the code points of '@', 64, and '.', 46, to the stack.
@ Terminate the program.

At the end of the program, the stack contents are printed as decimal integers with space-separation and a trailing linefeed.

I also tried for 5 with "@ and a suitable topology that lets the IP traverse more cells before hitting the " again, but the implicit cells (used to pad the code to a square) are ., so we can only ever print 2-digit numbers, and therefore we can't possibly get to 5 bytes of output with this technique.

answered May 24, 2017 at 6:22
\$\endgroup\$
1
\$\begingroup\$

BotEngine, 5 bytes

TIRES

(Or any other program of the same length which starts with a T)

Prints TRUE, followed by a trailing newline (which apparently counts for this question).

answered May 25, 2017 at 0:55
\$\endgroup\$
1
\$\begingroup\$

Perl 5, 7 bytes

say$"x6

$" contains a space by default, and x6 duplicates it six times. say prints and adds a newline, so this prints six spaces followed by a newline.

answered May 25, 2017 at 16:30
\$\endgroup\$
4
  • \$\begingroup\$ It seems that say requires a use declaration to enable it. \$\endgroup\$ Commented May 26, 2017 at 1:40
  • \$\begingroup\$ @ØrjanJohansen Normal execution of a perl one-liner is with the -E flag, which automatically enables all optional features, including say. That is, execute it like perl -E 'say$"x6' \$\endgroup\$ Commented May 26, 2017 at 5:50
  • \$\begingroup\$ Saying that "normal execution of a perl one-liner is with -E flag" isn't quite right. However, here on PPCG, we allow Perl one-lines to be ran with -E flag instead of the usual -e \$\endgroup\$ Commented May 29, 2017 at 14:16
  • \$\begingroup\$ @Dada Well, it's up to taste I suppose. There's rarely any reason not to use -E, so I'm in the habit of doing so. \$\endgroup\$ Commented May 29, 2017 at 19:58
1
\$\begingroup\$

MainRamCounter, 6 bytes

"a"e6R

This is a new language I am currently developing. It is based off of 3 storage spaces: Main (which does comparisons and math), Ram (which stores values), and counter (which is a counter).

Breakdown:

"a" push 97 to ram
e6 duplicate current ram 6 times
R output ram as string

Output:

aaaaaa
answered May 26, 2017 at 19:07
\$\endgroup\$
1
\$\begingroup\$

Chip, 78+3 = 81 bytes

Flag: -w

Code (Try it online!):

g*
,xZ.
`@'|
,xZ<
`@'|
,xZ<
`@'|
,xZ<
`@'`.
,xZ~<
`@','
,xZ^.
`@'t{*
,xZ~'
`@'

Out: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

This uses a binary counter to halt at the correct time.


11+3 = 14 bytes (uses version string)

Flag: -V

Code (anything will do, just need to fill the length):

gibberishes

Out (current interpreter, has trailing newline):
chip.py 0.1.2


40+3 = 43 bytes (error message, uses stderr)

Flag: -w

Code (apparently some of this is filler?):

!*T :Hello you! That shirt looks great!;

Out: 1:1 WARN: '!' (33) is not a valid character

answered May 31, 2017 at 21:54
\$\endgroup\$
1
\$\begingroup\$

Add++, 2 bytes

Noncompeting as language postdates challenge.

O

Try it online!

Outputs a 0 with a trailing newline.

answered Jun 9, 2017 at 6:57
\$\endgroup\$
1
\$\begingroup\$

C#, 53 bytes

Not short, but good enough:

string a="1";for(int i=0;i<53;i++){Console.Write(a);}

Some Facts I can't resist to post:

  • Fifty-three is the 16th prime number. It is also an Eisenstein prime, and a Sophie Germain prime.

  • 53 cannot be expressed as the sum of any integer and its base-10 digits, making 53 a self number.

  • 53 is the smallest prime number that does not divide the order of any sporadic group.

answered Jun 24, 2017 at 10:21
\$\endgroup\$
1
\$\begingroup\$

C#, 12 bytes

()=>1e11+"";

It returns 10^11, which is a 1 followed by 11 0-s, so 12 bytes long.

answered Jun 24, 2017 at 11:51
\$\endgroup\$
1
\$\begingroup\$

cQuents, 5 bytes

#3::$

Outputs 1,2,3. This works because of the mode, ::. :: prints the sequence up to n, which in this case is hardcoded in as 3. $ prints the current index - it could be replaced with any single digit. So, the interpreter prints out the first three items in the $ sequence, separated by the default delimiter, ,.

answered Jul 8, 2017 at 19:14
\$\endgroup\$
1
\$\begingroup\$

Common Lisp, 5 bytes

1e+01

in the Common Lisp REPL it produces 10.0 plus linefeed, for a total of 5 bytes.

Thanks to @MartinEnder for noting an error in the previous 4 bytes version!

answered Jul 9, 2017 at 9:39
\$\endgroup\$
0
1
...
4 5
6
7 8
...
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.