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>

  • 2
    Related. Related. – Martin Ender May 17 '17 at 11:19
  • 15
    "Your code must not be a quine" but... but... it's tagged quine – Okx May 17 '17 at 11:21
  • 3
    @Okx Because it's a generalised quine, i.e. the required output depends on the source code. – Martin Ender May 17 '17 at 11:22
  • 3
    @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 – Post Left Garf Hunter May 17 '17 at 22:37
  • 2
    @WheatWizard output by exit code is not a string, so it doesn't apply here. – Martin Ender May 18 '17 at 4:29

195 Answers 195

C (modern Linux), 19 bytes

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

When compiled and run, this prints:

Segmentation fault
  • 18
    This is brilliant :D – Beta Decay May 17 '17 at 22:13
  • 4
    this is more like "C + English language unix/posix OS ;)" – Florian Castellane May 18 '17 at 8:35
  • 5
    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. – Martin Rosenau May 18 '17 at 14:21
  • 8
    I joined the site just to upvote this answer. – Nitish May 19 '17 at 10:46
  • 6
    As impressive as this is, it's not really the C program that prints the output, but the shell it's running in. – Dennis May 23 '17 at 4:27

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.

  • 94
    This gives a whole new meaning to "picking the right language for the job". – Martin Ender May 17 '17 at 20:22
  • 4
    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. – OpiesDad May 18 '17 at 22:39
  • @OpiesDad Nice solution, I think you should post it as an answer, so I can upvote. – pajonk May 19 '17 at 5:23
  • 4
    @MartinEnder It amuses me how your speculation/potential joke is more upvoted than this answer (though it's close). – HyperNeutrino May 26 '17 at 14:42

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.

Bash (builtins only), 8 bytes

{e,,}cho

Prints cho cho and a newline.

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.

  • 24
    +1 For code telling me not to run it :P – Christopher May 17 '17 at 15:38

Mathematica, 2 bytes

4!

factorial

24

  • 1
    Gah! too clever. – tuskiomi May 17 '17 at 18:31
  • 2
    beat me to it! +1. (I think you should mention that this is in the REPL version of Mathematica.) – Greg Martin May 17 '17 at 20:18
  • 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...) – Mark Segal May 20 '17 at 19:18
  • 3
    @MarkSegal That would violate the no-quine-rule. – AlexR May 20 '17 at 19:48
  • 6
    Rules:..."...the code and the output must differ in at least one byte" – J42161217 May 20 '17 at 19:48

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.

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

Javascript ES6, 9 bytes

Using Template Strings

_=>`${_}`

f=

_=>`${_}`

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

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

Bash on Linux, 6

uname

(followed by a newline)

Outputs Linux followed by a newline.

  • 1
    Technically uname isn't a bash builtin - it's a separate executable – Jason Musgrove May 25 '17 at 11:13

Python 2, 9 bytes

print 1e5

The displayed output contains a trailing newline.

Try it online!

  • Do trailing newlines count as a character as far as output? Otherwise, this prints eight bytes. – OldBunny2800 May 18 '17 at 0:10
  • @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 – Luis Mendo May 18 '17 at 0:18

Pyramid Scheme, 74 bytes

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

Try it online!

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

  • 5
    Hey, are you trying to sell your language? If so, you're under arrest. -- The Cops – NoOneIsHere Jul 21 '17 at 21:58
  • 2
    @NoOneIsHere pardon? – Conor O'Brien Jul 21 '17 at 23:46
  • 2
    Sorry, it's called Pyramid Scheme, which is also the name of a type of scam. – NoOneIsHere Jul 22 '17 at 1:47
  • 1
    ohhhhhhhhhhhh rofl – Conor O'Brien Jul 22 '17 at 2:42
  • This is a beautiful language. – latias1290 Aug 6 '17 at 10:55

Python 2, 9 bytes

print{+1}

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

Try it online!

  • 9
    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. – xnor May 17 '17 at 20:56

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
  • 4
    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. – Roman Gräf May 17 '17 at 14:07
  • @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. – Zack C. May 17 '17 at 15:28
  • Could you not have a 1 byte program . which prints the unprintable NULL character? – Graviton May 17 '17 at 21:03
  • @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). – Zack C. May 17 '17 at 21:33
  • 24 bytes – Jo King Mar 10 at 4:37

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  ....@.8...@.....
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  T.@.....D.......
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.

  • This is wizardry... does this assume the byte order of the compiled assembly or something? – Patrick Roberts May 23 '17 at 9:49
  • Output on my system (Linux with GCC 6.3.1): U when compiling with -Df=main. U when compiling with main(){f();}. – MD XF May 23 '17 at 14:56
  • @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. – Dennis May 23 '17 at 15:26
  • @MDXF Found a shorter way to get a suitable memory address. It works on my Ubuntu 14.04 VPS now, but ymmv. – Dennis May 23 '17 at 17:09
  • @Dennis Works fine now (dang it). Bounty is yours if by the end of the week no one finds a shorter solution. – MD XF May 23 '17 at 18:02
up vote 15 down vote
+100

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
  • 6
    @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). – Dennis May 26 '17 at 0:00

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

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

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.

  • 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? – MD XF May 17 '17 at 21:58
  • 4
    @MDXF "Usual quine rules don't apply" – Rob Watts May 17 '17 at 22:48
  • 2
    @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. – Fatalize May 18 '17 at 7:25

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.

  • 1
    Is this true for all calculators? I'm sure they do constantly show the decimal point – Beta Decay May 18 '17 at 8:55
  • Isn't it 1. instead of 1x? Also this is a quine, which is disallowed by the rules. – Erik the Outgolfer May 18 '17 at 16:42
  • No, it's 1=, I messed up. I meant 1x than implicit equals, but I forgot that = is a button. – OldBunny2800 May 18 '17 at 18:48

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
  • 2
    ()->1E10-1+"" , "9.999999999E9" (13) saves three more bytes – JollyJoker May 23 '17 at 10:29
  • 1
    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). – Kevin Cruijssen Sep 18 '17 at 12:09

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.

  • 3ii doesn't expand until you press escape, so should that be three or four bytes (or keystrokes, rather)? – algmyr May 18 '17 at 4:43
  • @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. – DJMcMayhem May 18 '17 at 5:29

Batch, 12 bytes

@echo %OS%

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

Windows_NT
  • It seems that it's 11 bytes not 12. – Erik the Outgolfer May 24 '17 at 13:46
  • @EriktheOutgolfer cmd.exe will of course echo a CRLF after the Windows_NT, thus 12 bytes. – Neil May 24 '17 at 14:35
  • Then you should clarify? – Erik the Outgolfer May 24 '17 at 14:36

///, 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.

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.

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.

  • "which is an accepted output method" only for function solutions, not for full programs. – Martin Ender May 17 '17 at 11:30
  • @MartinEnder Would those solutions count as functions, then? Not really sure, as I don't often use functions here. – Okx May 17 '17 at 11:32
  • 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). – Martin Ender May 17 '17 at 11:33

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.

Charcoal, 2 bytes

→¹

Try it online!

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

  • Man charcoal's a really nifty language, I should learn it some time – Skidsdev May 17 '17 at 11:59

Befunge, 2 bytes

.@

Try it online!

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

C#, 22 16 bytes

()=>$"{1L<<50}";

-6 bytes thanks to Orjan Johansen, using long instead of int.

Outputs

1125899906842624

Alternately, if you allow an arbitrary parameter to be passed into the lambda:

C#, 21 15 bytes

_=>$"{1L<<49}";

Outputs

562949953421312
  • If you use long you can do it shorter with only one group: ()=>$"{1L<<50}";. Try it online! – Ørjan Johansen May 17 '17 at 23:49
  • Good job on posting such a short C# answer. You can also shave of a byte by using +"" instead of string interpolation. – LiefdeWen May 18 '17 at 8:16
  • Neither 1L<<50+"" or ""+1L<<50 works for me due to << having lower precedence than +, so would need to add parens making the length the same. – milk May 18 '17 at 19:37
  • 2
    Why do you include a semicolon? It's not part of the function. – LegionMammal978 May 21 '17 at 15:08

Excel, 7 bytes

=9^7&""

Produces a 7 digit number and then appends empty string

Uses general idea from pajonk in their answer [although obviously not the language trick :)]

  • 1
    Welcome to PPCG! I edited your header so that it gets picked up by the leaderboard. :) – Martin Ender May 19 '17 at 13:52
  • "Why not just make a 4 digit number?" The challenge states that the function must return a string. It can be checked by T function whether something is string in Excel - the first solution isn't, the second is. Anyway, upvote as promised. – pajonk May 20 '17 at 16:51
  • @pajonk Great point. I have taken the smaller solution out as I agree it does not meet the conditions. Thanks! – OpiesDad May 20 '17 at 21:19

NodeJS REPL, 4 bytes

Did someone say REPLs are languages?

*;;;

..._

(the underscore is actually a space character).

For anyone not familiar with the Node REPL, it thinks my program isn't complete, so it's prompting for the rest of the line.

  • You could also use !!!0, 1e2 or "" – powelles May 22 '17 at 19:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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