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 isab 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 rulesdon'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 aprogram or a function and use any of thestandard 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 anyprogramming language, but note thatthese loopholes are forbidden by default.

This is, so the shortest valid answer – measured inbytes – 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> <h2>Leaderboard</h2> <table> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody> </tbody> </table> </div><div> <h2>Winners by Language</h2> <table> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody> </tbody> </table> </div><table> <tbody> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table> <tbody> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

askedMay 17, 2017 at 11:17
Martin Ender's user avatar
\$\endgroup\$
20
  • 2
    \$\begingroup\$Related.Related.\$\endgroup\$CommentedMay 17, 2017 at 11:19
  • 1
    \$\begingroup\$@Mr.XcoderYes, if you declare them as such.\$\endgroup\$CommentedMay 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\$CommentedMay 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\$CommentedMay 17, 2017 at 22:37
  • 2
    \$\begingroup\$@WheatWizard output by exit code is not a string, so it doesn't apply here.\$\endgroup\$CommentedMay 18, 2017 at 4:29

292 Answers292

231
\$\begingroup\$

C (modern Linux), 19 bytes

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

When compiled and run, this prints:

Segmentation fault
answeredMay 17, 2017 at 21:54
MD XF's user avatar
\$\endgroup\$
17
  • 24
    \$\begingroup\$This is brilliant :D\$\endgroup\$CommentedMay 17, 2017 at 22:13
  • 7
    \$\begingroup\$this is more like "C + English language unix/posix OS ;)"\$\endgroup\$CommentedMay 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\$CommentedMay 18, 2017 at 14:21
  • 13
    \$\begingroup\$I joined the site just to upvote this answer.\$\endgroup\$CommentedMay 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\$CommentedMay 23, 2017 at 4:27
102
\$\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.

answeredMay 17, 2017 at 19:58
pajonk's user avatar
\$\endgroup\$
4
  • 132
    \$\begingroup\$This gives a whole new meaning to "picking the right language for the job".\$\endgroup\$CommentedMay 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\$CommentedMay 18, 2017 at 22:39
  • \$\begingroup\$@OpiesDad Nice solution, I think you should post it as an answer, so I can upvote.\$\endgroup\$CommentedMay 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\$CommentedMay 26, 2017 at 14:42
70
\$\begingroup\$

Bash (builtins only), 8 bytes

{e,,}cho

Printscho cho and a newline.

answeredMay 22, 2017 at 3:26
Anders Kaseorg's user avatar
\$\endgroup\$
1
  • 1
    \$\begingroup\$Like a train: choo choo!\$\endgroup\$CommentedFeb 18, 2022 at 8:34
63
\$\begingroup\$

Labyrinth, 4 bytes

!!>@

Try it online!

Prints0000

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.
answeredMay 17, 2017 at 11:35
Martin Ender's user avatar
\$\endgroup\$
1
  • 8
    \$\begingroup\$That is too clever. Have a +1, on the house!\$\endgroup\$CommentedMay 17, 2017 at 15:22
46
\$\begingroup\$

Retina, 2 bytes

no

Try it online!

Prints0 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.

answeredMay 17, 2017 at 11:59
Martin Ender's user avatar
\$\endgroup\$
0
38
\$\begingroup\$

Mathematica, 2 bytes

4!

factorial

24

answeredMay 17, 2017 at 12:17
ZaMoC's user avatar
\$\endgroup\$
5
  • 1
    \$\begingroup\$Gah! too clever.\$\endgroup\$CommentedMay 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\$CommentedMay 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\$CommentedMay 20, 2017 at 19:18
  • 4
    \$\begingroup\$@MarkSegal That would violate the no-quine-rule.\$\endgroup\$CommentedMay 20, 2017 at 19:48
  • 7
    \$\begingroup\$Rules:..."...the code and the output must differ in at least one byte"\$\endgroup\$CommentedMay 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            -666605944llama@llama:...code/c/ppcg121056samelen$ ./a.out           -1391039592llama@llama:...code/c/ppcg121056samelen$ ./a.out            1727404696llama@llama:...code/c/ppcg121056samelen$ ./a.out              10717352llama@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 atf's address.

answeredMay 17, 2017 at 12:31
Doorknob's user avatar
\$\endgroup\$
7
  • \$\begingroup\$I'm glad to see an answer that makes use of the varying-output rule. :)\$\endgroup\$CommentedMay 17, 2017 at 12:33
  • \$\begingroup\$Couldn't this segfault?\$\endgroup\$CommentedMay 17, 2017 at 16:50
  • \$\begingroup\$Where's the TIO link(s)?\$\endgroup\$CommentedMay 17, 2017 at 19:06
  • \$\begingroup\$@Daniel No, the number printed will come from the previous contents of the%esi register.\$\endgroup\$CommentedMay 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\$CommentedMay 18, 2017 at 7:12
31
\$\begingroup\$

Bash on Linux, 6

uname

(followed by a newline)

OutputsLinux followed by a newline.

answeredMay 17, 2017 at 16:02
Digital Trauma's user avatar
\$\endgroup\$
6
  • 2
    \$\begingroup\$Technicallyuname isn't a bash builtin - it's a separate executable\$\endgroup\$CommentedMay 25, 2017 at 11:13
  • 1
    \$\begingroup\$-1, and actually a builtin\$\endgroup\$CommentedAug 18, 2019 at 3:12
  • \$\begingroup\$@GammaFunction Where do you seeuname 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\$CommentedAug 21, 2019 at 16:27
  • 1
    \$\begingroup\$Idon't seeuname as a builtin. When I said "-1, and actually a builtin", I meant "This answer usesumask for -1 bytes, andumask is actually a builtin".\$\endgroup\$CommentedAug 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\$CommentedAug 21, 2019 at 17:00
27
\$\begingroup\$

Javascript ES6, 9 bytes

Using Template Strings

_=>`${_}`

f=_=>`${_}`console.log(f());console.log(typeof f());

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

Pyramid Scheme,7443 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 number28^28 = 33145523113253374862572728253364605812736, followed by a trailing newline.


Old version

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

Try it online!

Outputs71277303925397560663333806233294794013421332605135474842607729452115234375 =160651015 ** 9, or about 1074.

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

Python 2, 9 bytes

print{+1}

This printsset([1]) and a linefeed.

Try it online!

answeredMay 17, 2017 at 19:13
Dennis's user avatar
\$\endgroup\$
1
  • 15
    \$\begingroup\$From brute-forcing programs starting withprint, there are no shorter solutions, and the only 9-bytes ones are variants of this andLuis Mendo'sprint 1e5.\$\endgroup\$CommentedMay 17, 2017 at 20:56
24
\$\begingroup\$

Python 2, 9 bytes

print 1e5

The displayed output contains a trailing newline.

Try it online!

answeredMay 17, 2017 at 12:03
Luis Mendo's user avatar
\$\endgroup\$
2
  • \$\begingroup\$Do trailing newlines count as a character as far as output? Otherwise, this prints eight bytes.\$\endgroup\$CommentedMay 18, 2017 at 0:10
  • \$\begingroup\$@OldBunny2800 Yes, the challenge saysIf your output contains trailing newlines, those are part of the byte count. Anyway, I'll clarify that in my answer\$\endgroup\$CommentedMay 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
answeredMay 17, 2017 at 13:43
Zack C.'s user avatar
\$\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\$CommentedMay 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\$CommentedMay 17, 2017 at 15:28
  • \$\begingroup\$Could you not have a 1 byte program. which prints the unprintableNULL character?\$\endgroup\$CommentedMay 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\$CommentedMay 17, 2017 at 21:33
  • \$\begingroup\$24 bytes\$\endgroup\$CommentedMar 10, 2018 at 4:37
17
+100
\$\begingroup\$

C (Ideone), 14 bytes

f(){warn(0);}

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

prog: Success

C (GCC), 15 bytes

f(){warn(00);}

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

a.out: Success
answeredMay 25, 2017 at 8:05
Anders Kaseorg's user avatar
\$\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\$CommentedMay 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.

answeredMay 17, 2017 at 19:34
Zack C.'s user avatar
\$\endgroup\$
16
\$\begingroup\$

Basic Arithmetic Calculator, 2 bytes

1=

prints1., or:

    |    |    |  .

on those silly seven-segment displays.

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

answeredMay 18, 2017 at 0:27
AAM111's user avatar
\$\endgroup\$
6
  • 1
    \$\begingroup\$Is this true for all calculators? I'm sure they do constantly show the decimal point\$\endgroup\$CommentedMay 18, 2017 at 8:55
  • \$\begingroup\$Isn't it1. instead of1x? Also this is a quine, which is disallowed by the rules.\$\endgroup\$CommentedMay 18, 2017 at 16:42
  • \$\begingroup\$No, it's1=, I messed up. I meant1x than implicit equals, but I forgot that= is a button.\$\endgroup\$CommentedMay 18, 2017 at 18:48
  • \$\begingroup\$It only outputs1 on both my TI-36 and TI-84 CE. Do these not count as "basic" calculators?\$\endgroup\$CommentedJul 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\$CommentedAug 1, 2019 at 15:14
15
\$\begingroup\$

C (gcc),18 17 bytes

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

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

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 printsexec/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$ ./quineinux-x86-64.so.2$ ./quine | wc -c17

How it works

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

The first 640 bytes of the ELF are largely independent of the actual source code. For example, if the declaration off is followed bymain(){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/l00000240: 64 2d 6c 69 6e 75 78 2d 78 38 36 2d 36 34 2e 73  d-linux-x86-64.s00000250: 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 is0x238 and it is 27 bytes long. We only want to print 17 bytes (and the last one will be a newline if we useputs), so we add11 to the offset to get0x243, the offset ofinux-x86-64.so.2. Adding0x400000 and0x243 gives0x400243, the memory location ofinux-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.

answeredMay 23, 2017 at 4:45
Dennis's user avatar
\$\endgroup\$
13
  • \$\begingroup\$This is wizardry... does this assume the byte order of the compiled assembly or something?\$\endgroup\$CommentedMay 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 withmain(){f();}.\$\endgroup\$CommentedMay 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\$CommentedMay 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\$CommentedMay 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\$CommentedMay 23, 2017 at 18:02
14
\$\begingroup\$

Fourier,2622 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

answeredMay 17, 2017 at 18:04
Beta Decay's user avatar
\$\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\$CommentedSep 18, 2017 at 22:31
  • \$\begingroup\$@Christopher Huh, I didn't know that\$\endgroup\$CommentedSep 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 is0.

answeredMay 17, 2017 at 11:40
Fatalize's user avatar
\$\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\$CommentedMay 17, 2017 at 21:58
  • 4
    \$\begingroup\$@MDXF "Usual quine rules don't apply"\$\endgroup\$CommentedMay 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\$CommentedMay 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
answeredMay 18, 2017 at 14:30
Olivier Grégoire's user avatar
\$\endgroup\$
2
  • 2
    \$\begingroup\$()->1E10-1+"" ,"9.999999999E9" (13) saves three more bytes\$\endgroup\$CommentedMay 23, 2017 at 10:29
  • 1
    \$\begingroup\$You can save 1 byte by changing1e10 to1e9, or 2 bytes by usingan empty input instead of() like this:o->1e8-1+"" (outputs9.9999999E7; length & byte-count11).\$\endgroup\$CommentedSep 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.

answeredMay 17, 2017 at 11:20
Okx's user avatar
\$\endgroup\$
3
  • \$\begingroup\$"which is an accepted output method" only for function solutions, not for full programs.\$\endgroup\$CommentedMay 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\$CommentedMay 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\$CommentedMay 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
answeredMay 17, 2017 at 11:55
Neil's user avatar
\$\endgroup\$
3
  • \$\begingroup\$It seems that it's 11 bytes not 12.\$\endgroup\$CommentedMay 24, 2017 at 13:46
  • \$\begingroup\$@EriktheOutgolfercmd.exe will of course echo a CRLF after theWindows_NT, thus 12 bytes.\$\endgroup\$CommentedMay 24, 2017 at 14:35
  • \$\begingroup\$Then you should clarify?\$\endgroup\$CommentedMay 24, 2017 at 14:36
10
\$\begingroup\$

Hexagony, 3 bytes

o!@

Try it online!

Prints111.

Unfolded:

 o !@ . . . .

But the code is really just run in the ordero!@.

o   Set the memory edge to 111, the code point of 'o'.!   Print this value as a decimal integer.@   Terminate the program.
answeredMay 17, 2017 at 12:04
Martin Ender's user avatar
\$\endgroup\$
4
  • \$\begingroup\$I'm assuming this isn't using the basic ! to just print a 0?\$\endgroup\$CommentedNov 3, 2020 at 22:14
  • \$\begingroup\$@Underslash A program without@ wouldn't terminate.\$\endgroup\$CommentedNov 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\$CommentedNov 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\$CommentedNov 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:

3iii³i¬ac

These are all specific to V.

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

Well, uh...

Mornington Crescent, 1731 bytes

Take Northern Line to StockwellTake Victoria Line to Seven SistersTake Victoria Line to Green ParkTake Piccadilly Line to Green ParkTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to Russell SquareTake Piccadilly Line to King's Cross St. PancrasTake Metropolitan Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Hammersmith & City Line to King's Cross St. PancrasTake Circle Line to King's Cross St. PancrasTake Circle Line to King's Cross St. PancrasTake Circle Line to BankTake Circle Line to BankTake Northern Line to Mornington Crescent

Prints out the value of7^2048, which is1731 digits long.Try it online!Verify that it's actually1731 digits long!

answeredMay 2, 2020 at 19:30
Cloudy7's user avatar
\$\endgroup\$
1
  • \$\begingroup\$I like this answer a lot.\$\endgroup\$CommentedSep 18, 2020 at 14:45
8
\$\begingroup\$

///, 12 bytes

/a/bcd/aaaa/

Try it online!

This printsbcdbcdbcdbcd, and because this is 12 bytes, I've added aharmless/ to the end of the code to pad it out.

answeredMay 17, 2017 at 12:17
steenbergh's user avatar
\$\endgroup\$
1
  • \$\begingroup\$With only (back)slashes, 34 bytes:/\/\\/\\\\\\\\\\\\\//\/\\\\\\\\\\\\$\endgroup\$CommentedAug 7, 2021 at 22:44
8
\$\begingroup\$

Befunge, 2 bytes

.@

Try it online!

Prints0 with a trailing space.Also works in Befunge 98.

answeredMay 17, 2017 at 17:38
Martin Ender's user avatar
\$\endgroup\$
8
\$\begingroup\$

R, 7 bytes

mode(T)

Prints "logical"

answeredJun 25, 2017 at 11:05
Ivanneke's user avatar
\$\endgroup\$
1
  • \$\begingroup\$Welcome to PPCG!\$\endgroup\$CommentedJun 25, 2017 at 11:49
7
\$\begingroup\$

MATL, 2 bytes

H

There is a trailing newline.

Try it online!

Explanation

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

answeredMay 17, 2017 at 11:19
Luis Mendo's user avatar
\$\endgroup\$
7
\$\begingroup\$

Charcoal, 2 bytes

→¹

Try it online!

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

answeredMay 17, 2017 at 11:41
ASCII-only's user avatar
\$\endgroup\$
1
  • \$\begingroup\$Man charcoal's a really nifty language, I should learn it some time\$\endgroup\$CommentedMay 17, 2017 at 11:59

Your Answer

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.