112
\$\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\$
22
  • 2
    \$\begingroup\$ Related. Related. \$\endgroup\$ Commented May 17, 2017 at 11:19
  • 22
    \$\begingroup\$ "Your code must not be a quine" but... but... it's tagged quine \$\endgroup\$
    – Okx
    Commented May 17, 2017 at 11:21
  • 4
    \$\begingroup\$ @Okx Because it's a generalised quine, i.e. the required output depends on the source code. \$\endgroup\$ Commented May 17, 2017 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
    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

288 Answers 288

1
2 3 4 5
10
229
\$\begingroup\$

C (modern Linux), 19 bytes

main(){puts('s');}

When compiled and run, this prints:

Segmentation fault
\$\endgroup\$
17
  • 24
    \$\begingroup\$ This is brilliant :D \$\endgroup\$
    – Beta Decay
    Commented May 17, 2017 at 22:13
  • 7
    \$\begingroup\$ this is more like "C + English language unix/posix OS ;)" \$\endgroup\$ Commented May 18, 2017 at 8:35
  • 7
    \$\begingroup\$ I think it would be better to write "C, modern Linux" than just "C": Under Windows the error message is different and in old times Linux programs were even compiled in a way that the address 0x73 ('s') was readable so no exception was caused. \$\endgroup\$ Commented May 18, 2017 at 14:21
  • 13
    \$\begingroup\$ I joined the site just to upvote this answer. \$\endgroup\$
    – Nitish
    Commented May 19, 2017 at 10:46
  • 12
    \$\begingroup\$ As impressive as this is, it's not really the C program that prints the output, but the shell it's running in. \$\endgroup\$
    – Dennis
    Commented May 23, 2017 at 4:27
96
\$\begingroup\$

Excel, 11 bytes

Norwegian language version:

=SMÅ(13^9)

English language version (12 bytes):

=LOWER(17^9)

Generates n-digit number and converts to text by converting to lowercase.

\$\endgroup\$
4
  • 130
    \$\begingroup\$ This gives a whole new meaning to "picking the right language for the job". \$\endgroup\$ Commented May 17, 2017 at 20:22
  • 5
    \$\begingroup\$ This is a great idea. It would be shorter to do =9^7&"" which generates a 7 digit number in either language and is only 7 bytes. \$\endgroup\$
    – OpiesDad
    Commented May 18, 2017 at 22:39
  • \$\begingroup\$ @OpiesDad Nice solution, I think you should post it as an answer, so I can upvote. \$\endgroup\$
    – pajonk
    Commented May 19, 2017 at 5:23
  • 5
    \$\begingroup\$ @MartinEnder It amuses me how your speculation/potential joke is more upvoted than this answer (though it's close). \$\endgroup\$
    – hyperneutrino
    Commented May 26, 2017 at 14:42
69
\$\begingroup\$

Bash (builtins only), 8 bytes

{e,,}cho

Prints cho cho and a newline.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Like a train: choo choo! \$\endgroup\$
    – qwr
    Commented Feb 18, 2022 at 8:34
62
\$\begingroup\$

Labyrinth, 4 bytes

!!>@

Try it online!

Prints 0000

Explanation

!   Print an implicit 0 from the stack.
!   Print an implicit 0 from the stack.
>   Rotate the source code right by one cell, so the code now becomes

    @!!>

    The IP is moved along, so it's now at the end of the line, which is 
    a dead end. So the IP turns around and starts moving left.
!   Print an implicit 0 from the stack.
!   Print an implicit 0 from the stack.
@   Terminate the program.
\$\endgroup\$
1
  • 8
    \$\begingroup\$ That is too clever. Have a +1, on the house! \$\endgroup\$ Commented May 17, 2017 at 15:22
44
\$\begingroup\$

Retina, 2 bytes

no

Try it online!

Prints 0 and a linefeed.

There are a lot of 2-byte solutions, but I believe this is optimal. Retina by default always prints a trailing newline and getting rid of it takes too many bytes. So we'd have to find a 1-byte program that leaves the empty input unchanged. I believe the only program which does this is the program containing a single linefeed, which is therefore equal to the output and hence not permitted by the challenge.

The next simplest thing to do is to live with Retina outputting a single digit (the number of matches of some regex against the empty input), and we can do that with a lot of failing (or matching) 2-byte patterns.

\$\endgroup\$
1
  • 31
    \$\begingroup\$ +1 For code telling me not to run it :P \$\endgroup\$
    – user63187
    Commented May 17, 2017 at 15:38
37
\$\begingroup\$

Mathematica, 2 bytes

4!

factorial

24

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Gah! too clever. \$\endgroup\$
    – tuskiomi
    Commented May 17, 2017 at 18:31
  • 2
    \$\begingroup\$ beat me to it! +1. (I think you should mention that this is in the REPL version of Mathematica.) \$\endgroup\$ Commented May 17, 2017 at 20:18
  • \$\begingroup\$ If this is a reasonable answer, wouldn't the answer "1" also be a reasonable answer? (Putting '1' into Mathematica's REPL would return '1' too...) \$\endgroup\$
    – Mark Segal
    Commented May 20, 2017 at 19:18
  • 4
    \$\begingroup\$ @MarkSegal That would violate the no-quine-rule. \$\endgroup\$
    – AlexR
    Commented May 20, 2017 at 19:48
  • 7
    \$\begingroup\$ Rules:..."...the code and the output must differ in at least one byte" \$\endgroup\$
    – ZaMoC
    Commented May 20, 2017 at 19:48
32
\$\begingroup\$

C, 20 bytes

f(){printf("%20d");}

Outputs some number, padded with spaces to a length of 20. (What number? Whatever happens to come next in memory.)

Some sample runs on my system:

llama@llama:...code/c/ppcg121056samelen$ ./a.out 
           -666605944
llama@llama:...code/c/ppcg121056samelen$ ./a.out 
          -1391039592
llama@llama:...code/c/ppcg121056samelen$ ./a.out 
           1727404696
llama@llama:...code/c/ppcg121056samelen$ ./a.out 
             10717352
llama@llama:...code/c/ppcg121056samelen$ ./a.out 
           1485936232

It's a shame that the output can't be arbitrary bytes, because that would have allowed this 19 byte solution:

f(){write(1,f,19);}

which outputs 19 bytes of junk, starting at f's address.

\$\endgroup\$
7
  • \$\begingroup\$ I'm glad to see an answer that makes use of the varying-output rule. :) \$\endgroup\$ Commented May 17, 2017 at 12:33
  • \$\begingroup\$ Couldn't this segfault? \$\endgroup\$
    – Daniel
    Commented May 17, 2017 at 16:50
  • \$\begingroup\$ Where's the TIO link(s)? \$\endgroup\$ Commented May 17, 2017 at 19:06
  • \$\begingroup\$ @Daniel No, the number printed will come from the previous contents of the %esi register. \$\endgroup\$
    – Doorknob
    Commented May 17, 2017 at 20:03
  • 9
    \$\begingroup\$ @Doorknob but it's still undefined behavior, therefore a more sadistic compiler might do something entirely different here \$\endgroup\$ Commented May 18, 2017 at 7:12
31
\$\begingroup\$

Bash on Linux, 6

uname

(followed by a newline)

Outputs Linux followed by a newline.

\$\endgroup\$
6
  • 2
    \$\begingroup\$ Technically uname isn't a bash builtin - it's a separate executable \$\endgroup\$ Commented May 25, 2017 at 11:13
  • 1
    \$\begingroup\$ -1, and actually a builtin \$\endgroup\$ Commented Aug 18, 2019 at 3:12
  • \$\begingroup\$ @GammaFunction Where do you see uname as a bash builtin? Every distro I can lay my hands on right now it is a separate binary, including TIO. Conversely, as your linked answer shows, umask is a builtin in most/all shells. \$\endgroup\$ Commented Aug 21, 2019 at 16:27
  • 1
    \$\begingroup\$ I don't see uname as a builtin. When I said "-1, and actually a builtin", I meant "This answer uses umask for -1 bytes, and umask is actually a builtin". \$\endgroup\$ Commented Aug 21, 2019 at 16:30
  • 1
    \$\begingroup\$ @GammaFunction Sorry - I misunderstood the meaning of the "-1" in your comment - I'm used to those meaning downvote and a comment explaining why. \$\endgroup\$ Commented Aug 21, 2019 at 17:00
27
\$\begingroup\$

Javascript ES6, 9 bytes

Using Template Strings

_=>`${_}`

f=

_=>`${_}`

console.log(f());
console.log(typeof f());

\$\endgroup\$
8
  • \$\begingroup\$ Is undefined considered a string? \$\endgroup\$
    – Shaggy
    Commented May 17, 2017 at 11:44
  • 3
    \$\begingroup\$ @Shaggy See the edit. I am using String interpolation \$\endgroup\$
    – Weedoze
    Commented May 17, 2017 at 11:46
  • \$\begingroup\$ Wow this is my second post on PPCG and 14 upvotes ! Thanks \$\endgroup\$
    – Weedoze
    Commented May 18, 2017 at 6:03
  • 1
    \$\begingroup\$ Why simple whey you can have it difficult? (_=>_+''). \$\endgroup\$
    – GOTO 0
    Commented May 18, 2017 at 9:46
  • 1
    \$\begingroup\$ @GOTO0 Oh ok you keep the parenthesis. This is another option. I personally prefer mine hehe \$\endgroup\$
    – Weedoze
    Commented May 18, 2017 at 9:56
26
\$\begingroup\$

Pyramid Scheme, 74 43 42 bytes

Saved 31 bytes thanks to Khuldraeseth na'Barya! Saved 1 byte thanks to JoKing's redesigned solution!

  ^
 /^\
^---^
-^ ^-
 -^-
 /2\
/ 8 \
-----

Try it online! Outputs the 41-digit number 28^28 = 33145523113253374862572728253364605812736, followed by a trailing newline.


Old version

  ^
 / \
/out\
-----^
    /^\
   ^---^
  /1\ /9\
 /606\---
/51015\
-------

Try it online!

Outputs 71277303925397560663333806233294794013421332605135474842607729452115234375 = 160651015 ** 9, or about 1074.

\$\endgroup\$
8
  • 9
    \$\begingroup\$ Hey, are you trying to sell your language? If so, you're under arrest. -- The Cops \$\endgroup\$ Commented Jul 21, 2017 at 21:58
  • 2
    \$\begingroup\$ @NoOneIsHere pardon? \$\endgroup\$ Commented Jul 21, 2017 at 23:46
  • 3
    \$\begingroup\$ Sorry, it's called Pyramid Scheme, which is also the name of a type of scam. \$\endgroup\$ Commented Jul 22, 2017 at 1:47
  • 1
    \$\begingroup\$ ohhhhhhhhhhhh rofl \$\endgroup\$ Commented Jul 22, 2017 at 2:42
  • 3
    \$\begingroup\$ Implicit output gets you down to 43 bytes. \$\endgroup\$ Commented Jul 25, 2019 at 19:00
24
\$\begingroup\$

Python 2, 9 bytes

print{+1}

This prints set([1]) and a linefeed.

Try it online!

\$\endgroup\$
1
  • 15
    \$\begingroup\$ From brute-forcing programs starting with print, there are no shorter solutions, and the only 9-bytes ones are variants of this and Luis Mendo's print 1e5. \$\endgroup\$
    – xnor
    Commented May 17, 2017 at 20:56
23
\$\begingroup\$

Python 2, 9 bytes

print 1e5

The displayed output contains a trailing newline.

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Do trailing newlines count as a character as far as output? Otherwise, this prints eight bytes. \$\endgroup\$
    – AAM111
    Commented May 18, 2017 at 0:10
  • \$\begingroup\$ @OldBunny2800 Yes, the challenge says If your output contains trailing newlines, those are part of the byte count. Anyway, I'll clarify that in my answer \$\endgroup\$
    – Luis Mendo
    Commented May 18, 2017 at 0:18
19
\$\begingroup\$

brainfuck, 25 bytes

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

Try it online! Note: Requires an implementation with 8-bit unsigned cells

Output:

~~~~~}}}}}|||||{{{{{zzzzz

Explanation

--[         254
 -->+<]      /2 = 127 into the second cell
+++++[      Five times
 ->-.....<]  Print the second cell - 1 five times
\$\endgroup\$
5
  • 4
    \$\begingroup\$ There are many BF-variations like a 8-bit-cell, infite tape. or a limited tape and infinite cells. I'm pretty sure yours is a unsigned 8-bit cell model, but i think it'd be good if you include that into your answer. \$\endgroup\$ Commented May 17, 2017 at 14:07
  • \$\begingroup\$ @RomanGräf Good point! I usually do include that information if a non-standard implementation is required. This answer should work on any standard implementation (8-bit unsigned cells, any tape), but I'll add a note to clarify. \$\endgroup\$
    – Zack C.
    Commented May 17, 2017 at 15:28
  • \$\begingroup\$ Could you not have a 1 byte program . which prints the unprintable NULL character? \$\endgroup\$
    – Graviton
    Commented May 17, 2017 at 21:03
  • \$\begingroup\$ @Graviton That would violate the first rule of this challenge. However, that's a valid solution in a BF derivative that defaults to a printable value (see: my brainbool answer). \$\endgroup\$
    – Zack C.
    Commented May 17, 2017 at 21:33
  • \$\begingroup\$ 24 bytes \$\endgroup\$
    – Jo King
    Commented Mar 10, 2018 at 4:37
17
+100
\$\begingroup\$

C (Ideone), 14 bytes

f(){warn(0);}

On Ideone, which names its executable prog, this outputs the following with a trailing newline.

prog: Success

C (GCC), 15 bytes

f(){warn(00);}

Because GCC writes an executable named a.out by default (in the absence of additional flags that would cost bytes), this outputs the following with a trailing newline.

a.out: Success
\$\endgroup\$
1
  • 7
    \$\begingroup\$ @MDXF The spec says program or function, so a function submission is perfectly valid. Since the filename isn't chosen by the user here (both Ideone and gcc have defaults), I think this is fine (personal opinion). \$\endgroup\$
    – Dennis
    Commented May 26, 2017 at 0:00
16
\$\begingroup\$

Self-modifying Brainfuck, 5 bytes

<[.<]

Try it online!

Output:

]<.[<

Explanation:

Really simple, prints the source in reverse. In SMBF, the content of the program is stored on the tape, to the left of the initial position of the pointer. Gliding left and printing will output the source code backwards.

Since reading source is allowed in this challenge, this should definitely be within the rules.

\$\endgroup\$
16
\$\begingroup\$

Basic Arithmetic Calculator, 2 bytes

1=

prints 1., or:

    |
    |
    |  .

on those silly seven-segment displays.

To reproduce, pick up any random calculator; they all have this programming language installed somehow.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Is this true for all calculators? I'm sure they do constantly show the decimal point \$\endgroup\$
    – Beta Decay
    Commented May 18, 2017 at 8:55
  • \$\begingroup\$ Isn't it 1. instead of 1x? Also this is a quine, which is disallowed by the rules. \$\endgroup\$ Commented May 18, 2017 at 16:42
  • \$\begingroup\$ No, it's 1=, I messed up. I meant 1x than implicit equals, but I forgot that = is a button. \$\endgroup\$
    – AAM111
    Commented May 18, 2017 at 18:48
  • \$\begingroup\$ It only outputs 1 on both my TI-36 and TI-84 CE. Do these not count as "basic" calculators? \$\endgroup\$ Commented Jul 31, 2019 at 18:58
  • \$\begingroup\$ No, a TI 84 is not an arithmetic calculator, it’s a graphing calculator. I don’t know about the 36, but I’m pretty sure it’s a scientific calculator. This answer is for four-function calculators. \$\endgroup\$
    – AAM111
    Commented Aug 1, 2019 at 15:14
15
\$\begingroup\$

C (gcc), 18 17 bytes

f(){puts('@C');}

Note that there's an STX byte (0x02) between @ and C.

Try it online!

Portability

This has been tested with gcc 6.3.1 and clang 3.9.1 on Fedora 25, gcc 4.8.4 on Ubuntu 14.04.4, and gcc 4.8.3 on openSUSE 13.2, where it prints the following output.

inux-x86-64.so.2

I expect this to produce the same output with all versions of gcc, as long as it compiles to an executable of the following type.

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2

Different platforms will require a different memory address and possibly a different order for the bytes in the multi-character character constant.

For example, replacing @\2C with @\2\4 prints exec/ld-elf.so.1 and a newline on FreeBSD 11 with clang 3.8.0.

Offline verification

$ printf "%b\n" "f(){puts('@\2C');}main(){f();}" > quine.c
$ gcc -w -o quine quine.c
$ ./quine
inux-x86-64.so.2
$ ./quine | wc -c
17

How it works

By default, ld uses 0x400000 as the base address of the text segment, meaning that we can find the ELF's content starting at memory address 0x400000.

The first 640 bytes of the ELF are largely independent of the actual source code. For example, if the declaration of f is followed by main(){f();} and nothing else, they look as follows.

00000000: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  .ELF............
00000010: 02 00 3e 00 01 00 00 00 00 04 40 00 00 00 00 00  ..>.......@.....
00000020: 40 00 00 00 00 00 00 00 e8 19 00 00 00 00 00 00  @...............
00000030: 00 00 00 00 40 00 38 00 09 00 40 00 1e 00 1b 00  [email protected]...@.....
00000040: 06 00 00 00 05 00 00 00 40 00 00 00 00 00 00 00  ........@.......
00000050: 40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00  @.@.....@.@.....
00000060: f8 01 00 00 00 00 00 00 f8 01 00 00 00 00 00 00  ................
00000070: 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00  ................
00000080: 38 02 00 00 00 00 00 00 38 02 40 00 00 00 00 00  8.......8.@.....
00000090: 38 02 40 00 00 00 00 00 1c 00 00 00 00 00 00 00  8.@.............
000000a0: 1c 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00  ................
000000b0: 01 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00  ................
000000c0: 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 00  ..@.......@.....
000000d0: 04 07 00 00 00 00 00 00 04 07 00 00 00 00 00 00  ................
000000e0: 00 00 20 00 00 00 00 00 01 00 00 00 06 00 00 00  .. .............
000000f0: 08 0e 00 00 00 00 00 00 08 0e 60 00 00 00 00 00  ..........`.....
00000100: 08 0e 60 00 00 00 00 00 1c 02 00 00 00 00 00 00  ..`.............
00000110: 20 02 00 00 00 00 00 00 00 00 20 00 00 00 00 00   ......... .....
00000120: 02 00 00 00 06 00 00 00 20 0e 00 00 00 00 00 00  ........ .......
00000130: 20 0e 60 00 00 00 00 00 20 0e 60 00 00 00 00 00   .`..... .`.....
00000140: d0 01 00 00 00 00 00 00 d0 01 00 00 00 00 00 00  ................
00000150: 08 00 00 00 00 00 00 00 04 00 00 00 04 00 00 00  ................
00000160: 54 02 00 00 00 00 00 00 54 02 40 00 00 00 00 00  T.......T.@.....
00000170: 54 02 40 00 00 00 00 00 44 00 00 00 00 00 00 00  [email protected].......
00000180: 44 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00  D...............
00000190: 50 e5 74 64 04 00 00 00 b0 05 00 00 00 00 00 00  P.td............
000001a0: b0 05 40 00 00 00 00 00 b0 05 40 00 00 00 00 00  ..@.......@.....
000001b0: 3c 00 00 00 00 00 00 00 3c 00 00 00 00 00 00 00  <.......<.......
000001c0: 04 00 00 00 00 00 00 00 51 e5 74 64 06 00 00 00  ........Q.td....
000001d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
000001f0: 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00  ................
00000200: 52 e5 74 64 04 00 00 00 08 0e 00 00 00 00 00 00  R.td............
00000210: 08 0e 60 00 00 00 00 00 08 0e 60 00 00 00 00 00  ..`.......`.....
00000220: f8 01 00 00 00 00 00 00 f8 01 00 00 00 00 00 00  ................
00000230: 01 00 00 00 00 00 00 00 2f 6c 69 62 36 34 2f 6c  ......../lib64/l
00000240: 64 2d 6c 69 6e 75 78 2d 78 38 36 2d 36 34 2e 73  d-linux-x86-64.s
00000250: 6f 2e 32 00 04 00 00 00 10 00 00 00 01 00 00 00  o.2.............
00000260: 47 4e 55 00 00 00 00 00 02 00 00 00 06 00 00 00  GNU.............
00000270: 20 00 00 00 04 00 00 00 14 00 00 00 03 00 00 00   ...............

Using, e.g., main(int c, char**v){f();} instead changes some bytes, but not the offset of the string /lib64/ld-linux-x86-64.so.2, which we'll use to produce output.

The offset of said string is 0x238 and it is 27 bytes long. We only want to print 17 bytes (and the last one will be a newline if we use puts), so we add 11 to the offset to get 0x243, the offset of inux-x86-64.so.2. Adding 0x400000 and 0x243 gives 0x400243, the memory location of inux-x86-64.so.2.

To obtain this memory address, we can use multi-character character constants, which exhibit implementation-defined behavior. 0x400243 is (64)(2)(67) in base 256 and gcc's multi-character character constants use big-endian byte order, so '@\2C' yields the memory address of the desired string.

Finally, puts prints the (null-terminated) sting at that memory location and a trailing newline, creating 17 bytes of output.

\$\endgroup\$
13
  • \$\begingroup\$ This is wizardry... does this assume the byte order of the compiled assembly or something? \$\endgroup\$ Commented May 23, 2017 at 9:49
  • \$\begingroup\$ Output on my system (Linux with GCC 6.3.1): U when compiling with -Df=main. U when compiling with main(){f();}. \$\endgroup\$
    – MD XF
    Commented May 23, 2017 at 14:56
  • \$\begingroup\$ @PatrickRoberts At this point, I'm not really sure what the assumptions are. Since it pokes around in the assembled ELF file, it pretty much depends on everything the compiler writes before the actual code. \$\endgroup\$
    – Dennis
    Commented May 23, 2017 at 15:26
  • \$\begingroup\$ @MDXF Found a shorter way to get a suitable memory address. It works on my Ubuntu 14.04 VPS now, but ymmv. \$\endgroup\$
    – Dennis
    Commented May 23, 2017 at 17:09
  • \$\begingroup\$ @Dennis Works fine now (dang it). Bounty is yours if by the end of the week no one finds a shorter solution. \$\endgroup\$
    – MD XF
    Commented May 23, 2017 at 18:02
14
\$\begingroup\$

Fourier, 26 22 20 bytes

5^(`na`&i)` Batman!`

Try it on FourIDE!

Outputs:

nananananana Batman!

For proper capitalisation, it's 4 extra bytes:

`N`7^(`an`i^~i)`a Batman!`

Try it on FourIDE!

Nanananananananana Batman!

R.I.P. Adam West

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You don't have to include NC (only if you made string printing for this challenge (and that would be silly) \$\endgroup\$
    – user63187
    Commented Sep 18, 2017 at 22:31
  • \$\begingroup\$ @Christopher Huh, I didn't know that \$\endgroup\$
    – Beta Decay
    Commented Sep 19, 2017 at 6:21
12
\$\begingroup\$

Brachylog, 1 byte

w

Try it online!

Explanation

w is the built-in "write". Here, it will write the Input. Since the Input is a free variable, w will label it as an integer before printing. The first integer it tries is 0.

\$\endgroup\$
3
  • \$\begingroup\$ Here, it will write the Input. Is 'the Input' the program itself? Doesn't this count as reading the source, which is by default cheating in a quine? \$\endgroup\$
    – MD XF
    Commented May 17, 2017 at 21:58
  • 4
    \$\begingroup\$ @MDXF "Usual quine rules don't apply" \$\endgroup\$
    – Rob Watts
    Commented May 17, 2017 at 22:48
  • 3
    \$\begingroup\$ @MDXF The Input is a special Brachylog variable that you can set when calling a Brachylog program. It goes into the Input part of TryItOnline. Here we don't set anything to the Input, so it is effectively a variable. It is not the program. \$\endgroup\$
    – Fatalize
    Commented May 18, 2017 at 7:25
12
\$\begingroup\$

Java (OpenJDK 8), 11 bytes

o->1e8-1+""

Try it online!

Output:

9.9999999E7

Just a tad more elaborate than the obvious answer, ()->"".format("%23s",0).

Saves

  • 18 -> 16 bytes: More advantageous combination of rounding and power of 10, thanks to PunPun1000
  • 16 -> 13 bytes: better formula, thanks to JollyJoker
  • 13 -> 11 bytes: improved formula, thanks to Kevin Cruijssen
\$\endgroup\$
2
  • 2
    \$\begingroup\$ ()->1E10-1+"" , "9.999999999E9" (13) saves three more bytes \$\endgroup\$
    – JollyJoker
    Commented May 23, 2017 at 10:29
  • 1
    \$\begingroup\$ You can save 1 byte by changing 1e10 to 1e9, or 2 bytes by using an empty input instead of () like this: o->1e8-1+"" (outputs 9.9999999E7; length & byte-count 11). \$\endgroup\$ Commented Sep 18, 2017 at 12:09
10
\$\begingroup\$

05AB1E, 1 byte

õ

Outputs a single newline. õ pushes an empty string, and it is implicitly outputted with a newline.

Try it online!

Some other 2 byte solutions, for your viewing pleasure (the output is in the brackets, and all output has a trailing newline):

X, (1)
Y, (2)
¾, (0)
¼, (1)
¶, (newline)
ð, (space)
Î, (0)

There are way more 2 byte solutions though.

\$\endgroup\$
3
  • \$\begingroup\$ "which is an accepted output method" only for function solutions, not for full programs. \$\endgroup\$ Commented May 17, 2017 at 11:30
  • \$\begingroup\$ @MartinEnder Would those solutions count as functions, then? Not really sure, as I don't often use functions here. \$\endgroup\$
    – Okx
    Commented May 17, 2017 at 11:32
  • \$\begingroup\$ I don't know enough about 05AB1E but they're only considered functions if they are actually expressions that evaluate to a function object (which I doubt they do since using them immediately causes the command to be executed). \$\endgroup\$ Commented May 17, 2017 at 11:33
10
\$\begingroup\$

Batch, 12 bytes

@echo %OS%

Byte count includes trailing newline for both script and output, which is

Windows_NT
\$\endgroup\$
3
  • \$\begingroup\$ It seems that it's 11 bytes not 12. \$\endgroup\$ Commented May 24, 2017 at 13:46
  • \$\begingroup\$ @EriktheOutgolfer cmd.exe will of course echo a CRLF after the Windows_NT, thus 12 bytes. \$\endgroup\$
    – Neil
    Commented May 24, 2017 at 14:35
  • \$\begingroup\$ Then you should clarify? \$\endgroup\$ Commented May 24, 2017 at 14:36
10
\$\begingroup\$

Hexagony, 3 bytes

o!@

Try it online!

Prints 111.

Unfolded:

 o !
@ . .
 . .

But the code is really just run in the order o!@.

o   Set the memory edge to 111, the code point of 'o'.
!   Print this value as a decimal integer.
@   Terminate the program.
\$\endgroup\$
4
  • \$\begingroup\$ I'm assuming this isn't using the basic ! to just print a 0? \$\endgroup\$
    – Underslash
    Commented Nov 3, 2020 at 22:14
  • \$\begingroup\$ @Underslash A program without @ wouldn't terminate. \$\endgroup\$ Commented Nov 4, 2020 at 9:17
  • \$\begingroup\$ Oh right I am dumb. I think I thought that it would just run forever, but then I realized that it would just loop back to the 1st line instead of the last one. \$\endgroup\$
    – Underslash
    Commented Nov 5, 2020 at 0:53
  • \$\begingroup\$ @Underslash In a 1-byte program there isn't even a "last line", because that fits in a 1x1x1 hexagon, so a 1-byte program just repeatedly executes its only command, whatever that is (unless it terminates due to @ or a division-by-zero error). \$\endgroup\$ Commented Nov 11, 2020 at 21:13
9
\$\begingroup\$

V/vim, 1 byte

o

This prints a single newline.

Try it online!

There are a bunch of variants on this that would work too. For example,

O

in vim, and

Ä
ä
ï
Ï

in V.

There are also many many many three byte solutions. For example:

3ii
i³i
¬ac

These are all specific to V.

\$\endgroup\$
2
  • \$\begingroup\$ 3ii doesn't expand until you press escape, so should that be three or four bytes (or keystrokes, rather)? \$\endgroup\$
    – algmyr
    Commented May 18, 2017 at 4:43
  • \$\begingroup\$ @algmyr In vim, you are correct. It would have to be 4ii<ESC> However V implicitly fills in the escape at the end of the program. \$\endgroup\$
    – DJMcMayhem
    Commented May 18, 2017 at 5:29
9
\$\begingroup\$

Well, uh...

Mornington Crescent, 1731 bytes

Take Northern Line to Stockwell
Take Victoria Line to Seven Sisters
Take Victoria Line to Green Park
Take Piccadilly Line to Green Park
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to Russell Square
Take Piccadilly Line to King's Cross St. Pancras
Take Metropolitan Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Hammersmith & City Line to King's Cross St. Pancras
Take Circle Line to King's Cross St. Pancras
Take Circle Line to King's Cross St. Pancras
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Prints out the value of 7^2048, which is 1731 digits long. Try it online! Verify that it's actually 1731 digits long!

\$\endgroup\$
1
  • \$\begingroup\$ I like this answer a lot. \$\endgroup\$
    – Razetime
    Commented Sep 18, 2020 at 14:45
8
\$\begingroup\$

///, 12 bytes

/a/bcd/aaaa/

Try it online!

This prints bcdbcdbcdbcd, and because this is 12 bytes, I've added a harmless / to the end of the code to pad it out.

\$\endgroup\$
1
  • \$\begingroup\$ With only (back)slashes, 34 bytes: /\/\\/\\\\\\\\\\\\\//\/\\\\\\\\\\\ \$\endgroup\$
    – tjjfvi
    Commented Aug 7, 2021 at 22:44
8
\$\begingroup\$

Befunge, 2 bytes

.@

Try it online!

Prints 0 with a trailing space. Also works in Befunge 98.

\$\endgroup\$
8
\$\begingroup\$

R, 7 bytes

mode(T)

Prints "logical"

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Commented Jun 25, 2017 at 11:49
7
\$\begingroup\$

MATL, 2 bytes

H

There is a trailing newline.

Try it online!

Explanation

Clipboard H contains number 2 by default. H pushes that content to the stack, which gets implicitly displayed with a trailing newline.

\$\endgroup\$
7
\$\begingroup\$

Charcoal, 2 bytes

→¹

Try it online!

Prints a length-1 horizontal line of - to the right, and a newline.

\$\endgroup\$
1
  • \$\begingroup\$ Man charcoal's a really nifty language, I should learn it some time \$\endgroup\$
    – Mayube
    Commented May 17, 2017 at 11:59
1
2 3 4 5
10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.