Output with the same length as the code

97

12

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>

Martin Ender

Posted 8 years ago

Reputation: 184 808

2Related. Related. – Martin Ender – 8 years ago

18"Your code must not be a quine" but... but... it's tagged [tag:quine] – Okx – 8 years ago

4@Okx Because it's a generalised quine, i.e. the required output depends on the source code. – Martin Ender – 8 years ago

@MartinEnder Can we use REPL languages? – Mr. Xcoder – 8 years ago

1

@Mr.Xcoder Yes, if you declare them as such.

– Martin Ender – 8 years ago

No tabs (0x09) allowed in output? – jaxad0127 – 8 years ago

1@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. – Martin Ender – 8 years ago

@jaxad0127 In retrospect, I guess I could (or should) have allowed them, but now that there are already 70 answers, I don't want to make everyone go back and check if they can save bytes if I allow another character in the output. – Martin Ender – 8 years ago

About writing a function that takes no input, is it OK to produce a function that gives the right length when called with no inputs, even though it could be called with one or more inputs? – xnor – 8 years ago

@xnor sure, I guess. That's what all functions in some languages like JavaScript are like, aren't they? – Martin Ender – 8 years ago

@MartinEnder I was looking to submit Python's bool (with an extra space), which when called as just bool () on no inputs produces False. Both have length 5. Would that be valid? – xnor – 8 years ago

@xnor Neat idea, but functions need to return a string, not an object with a string representation of the required length. – Martin Ender – 8 years ago

4

@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 Rock Garf Hunter – 8 years ago

2@WheatWizard output by exit code is not a string, so it doesn't apply here. – Martin Ender – 8 years ago

Was this question designed to mess with the heads of those people who get crazy high scores on questions by using languages which consist of all 0's and the file-length is the actual program? They could be printing a long time! – Cort Ammon – 8 years ago

@CortAmmon I don't see why this should be worse for them than an ordinary quine. – Ørjan Johansen – 8 years ago

Umm, when can we expect to see a winner declared? :3 – Koishore Roy – 8 years ago

1

@KoishoreRoy I don't accept answers for code golf. That just pins a (probably very uninteresting) 1-byte solution to the top. If anyone wants to see the overall winner, they can use the leaderboard (which actually shows 25 tied answers).

– Martin Ender – 8 years ago

@MartinEnder thanks for clarifying :) – Koishore Roy – 8 years ago

I've changed [tag:quine] to [tag:self-referential] as per the new tag proposal on meta

– Jo King – 7 years ago

Answers

205

C (modern Linux), 19 bytes

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

When compiled and run, this prints:

Segmentation fault

MD XF

Posted 8 years ago

Reputation: 11 605

20This is brilliant :D – Beta Decay – 8 years ago

4this is more like "C + English language unix/posix OS ;)" – Florian Castellane – 8 years ago

4This is definitely among the greatest answers I've seen on this site, excellent meme. – RageCage – 8 years ago

5I 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 – 8 years ago

1How does that work? – Cyoce – 8 years ago

3@Cyoce puts takes a string as its only variable. A string literal is enclosed by double-quotes, e.g. "this is a string literal". A character literal is enclosed by single-quotes, e.g. 's'. Since puts is called explicitly, the compiler doesn't know what kind of variable puts wants, so it just passes the character literal, resulting in a segmentation fault (SIGSEGV). – MD XF – 8 years ago

9I joined the site just to upvote this answer. – Nitish – 8 years ago

Are there other locales which generate a 16-18 long error message? – 12431234123412341234123 – 8 years ago

1@12431234123412341234123 Trying to steal my answer? :P Not that I know of, this is the shortest. Some locales will print Segmentation fault (core dumped), others will print Segmentation Fault (SIGSEGV), some will print stuff along the lines of Program received SIGSEGV, others will print Invalid memory reference (SIGSEGV). – MD XF – 8 years ago

I would love to have reactions as in Facebook, this is brilliant and hilarious – Rodrigo – 8 years ago

Does output to /dev/stderr count? – agc – 8 years ago

1@agc Note that if you print the result, you may choose to print it either to the standard output or the standard error stream. – MD XF – 8 years ago

7As impressive as this is, it's not really the C program that prints the output, but the shell it's running in. – Dennis – 8 years ago

@Dennis C (modern Linux) – MD XF – 8 years ago

2On modern Linux, the program is still not printing the message, so this is not a pure C submission. – Dennis – 8 years ago

@Dennis Exactly. That's the main reason I included Linux in the title. C is raising the exception, the modern Linux kernel is doing the actual printing. – MD XF – 8 years ago

2

@MDXF It really is the shell, not the kernel (see my other comment).

– Anders Kaseorg – 8 years ago

80

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.

pajonk

Posted 8 years ago

Reputation: 2 480

107This gives a whole new meaning to "picking the right language for the job". – Martin Ender – 8 years ago

4This 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 – 8 years ago

@OpiesDad Nice solution, I think you should post it as an answer, so I can upvote. – pajonk – 8 years ago

4@MartinEnder It amuses me how your speculation/potential joke is more upvoted than this answer (though it's close). – HyperNeutrino – 8 years ago

55

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.

Martin Ender

Posted 8 years ago

Reputation: 184 808

6That is too clever. Have a +1, on the house! – caird coinheringaahing – 8 years ago

55

Bash (builtins only), 8 bytes

{e,,}cho

Prints cho cho and a newline.

Anders Kaseorg

Posted 8 years ago

Reputation: 29 242

40

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.

Martin Ender

Posted 8 years ago

Reputation: 184 808

27+1 For code telling me not to run it :P – Christopher – 8 years ago

33

Mathematica, 2 bytes

4!

factorial

24

J42161217

Posted 8 years ago

Reputation: 15 931

1Gah! too clever. – tuskiomi – 8 years ago

2

beat me to it! +1. (I think you should mention that this is in the REPL version of Mathematica.)

– Greg Martin – 8 years ago

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 – 8 years ago

3@MarkSegal That would violate the no-quine-rule. – AlexR – 8 years ago

6Rules:..."...the code and the output must differ in at least one byte" – J42161217 – 8 years ago

29

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.

Doorknob

Posted 8 years ago

Reputation: 68 138

I'm glad to see an answer that makes use of the varying-output rule. :) – Martin Ender – 8 years ago

Couldn't this segfault? – Daniel – 8 years ago

Where's the TIO link(s)? – CalculatorFeline – 8 years ago

@Daniel No, the number printed will come from the previous contents of the %esi register. – Doorknob – 8 years ago

The possibility of this segfault-ing inspired my answer (19 bytes), thanks :D

– MD XF – 8 years ago

9@Doorknob but it's still undefined behavior, therefore a more sadistic compiler might do something entirely different here – Display Name – 8 years ago

Doing this with main always outputs the same... – Mega Man – 8 years ago

29

Bash on Linux, 6

uname

(followed by a newline)

Outputs Linux followed by a newline.

Digital Trauma

Posted 8 years ago

Reputation: 64 644

2Technically uname isn't a bash builtin - it's a separate executable – Jason Musgrove – 8 years ago

-1, and actually a builtin – GammaFunction – 6 years ago

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

– Digital Trauma – 6 years ago

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". – GammaFunction – 6 years ago

@GammaFunction Sorry - I misunderstood the meaning of the "-1" in your comment - I'm used to those meaning downvote and a comment explaining why. – Digital Trauma – 6 years ago

I figured you did, I'm happy to clarify. – GammaFunction – 6 years ago

27

Javascript ES6, 9 bytes

Using Template Strings

_=>`${_}`

f=

_=>`${_}`

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

Weedoze

Posted 8 years ago

Reputation: 931

Is undefined considered a string? – Shaggy – 8 years ago

3@Shaggy See the edit. I am using String interpolation – Weedoze – 8 years ago

Wow this is my second post on PPCG and 14 upvotes ! Thanks – Weedoze – 8 years ago

1Why simple whey you can have it difficult? (_=>_+''). – GOTO 0 – 8 years ago

@GOTO0 Because the rules... undefined is 9 bytes long – Weedoze – 8 years ago

@Weedoze You're trolling now, right? – GOTO 0 – 8 years ago

1@GOTO0 Oh ok you keep the parenthesis. This is another option. I personally prefer mine hehe – Weedoze – 8 years ago

24

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.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

6Hey, are you trying to sell your language? If so, you're under arrest. -- The Cops – NoOneIsHere – 8 years ago

2@NoOneIsHere pardon? – Conor O'Brien – 8 years ago

3Sorry, it's called Pyramid Scheme, which is also the name of a type of scam. – NoOneIsHere – 8 years ago

1ohhhhhhhhhhhh rofl – Conor O'Brien – 8 years ago

This is a beautiful language. – latias1290 – 8 years ago

1

Implicit output gets you down to 43 bytes.

– Khuldraeseth na'Barya – 6 years ago

142 bytes – Jo King – 6 years ago

@JoKing Wow! That's a really nice looking pyramid!! – Conor O'Brien – 6 years ago

23

Python 2, 9 bytes

print 1e5

The displayed output contains a trailing newline.

Try it online!

Luis Mendo

Posted 8 years ago

Reputation: 87 464

Do trailing newlines count as a character as far as output? Otherwise, this prints eight bytes. – OldBunny2800 – 8 years ago

@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 – 8 years ago

23

Python 2, 9 bytes

print{+1}

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

Try it online!

Dennis

Posted 8 years ago

Reputation: 196 637

12

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 – 8 years ago

18

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

Zack C.

Posted 8 years ago

Reputation: 491

4There 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 – 8 years ago

@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. – 8 years ago

Could you not have a 1 byte program . which prints the unprintable NULL character? – Graviton – 8 years ago

@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. – 8 years ago

24 bytes – Jo King – 7 years ago

16

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

Anders Kaseorg

Posted 8 years ago

Reputation: 29 242

7@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 – 8 years ago

15

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.

Dennis

Posted 8 years ago

Reputation: 196 637

This is wizardry... does this assume the byte order of the compiled assembly or something? – Patrick Roberts – 8 years ago

Output on my system (Linux with GCC 6.3.1): U when compiling with -Df=main. U when compiling with main(){f();}. – MD XF – 8 years ago

@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 – 8 years ago

@MDXF Found a shorter way to get a suitable memory address. It works on my Ubuntu 14.04 VPS now, but ymmv. – Dennis – 8 years ago

@Dennis Works fine now (dang it). Bounty is yours if by the end of the week no one finds a shorter solution. – MD XF – 8 years ago

What if the interpreter is not /lib64/ld-linux-x86-64.so.2? Will this work on Windows systems with MinGW? You should probably include 64-bit Linux in the header. – MD XF – 8 years ago

It has to be compiled to an ELF of this version, but the compiled program can be run anywhere as long as your platform is able to execute it. I have no idea how MinGW works, nor a Windows computer to test it on. – Dennis – 8 years ago

C (ELF gcc/clang), perhaps? – Ørjan Johansen – 8 years ago

@ØrjanJohansen That's not really enough, as the interpreter has to be /lib64/ld-linux-x86-64.so.2; even a different directory structure would screw it up. I'd rather have a simple header and the details in the body. – Dennis – 8 years ago

Quoting the OP, 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.. Well, it's definitely shorter to read the source (well, not source, but the actual compiled program) in this case :P – MD XF – 8 years ago

@MDXF Guess again.

– Dennis – 8 years ago

@Dennis Is that valid, though? It breaks a few of the standard loopholes. – MD XF – 8 years ago

Morpheus smiles upon you – Patrick Roberts – 8 years ago

13

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

Beta Decay

Posted 8 years ago

Reputation: 21 478

1You don't have to include NC (only if you made string printing for this challenge (and that would be silly) – Christopher – 7 years ago

@Christopher Huh, I didn't know that – Beta Decay – 7 years ago

13

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.

Zack C.

Posted 8 years ago

Reputation: 491

13

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.

OldBunny2800

Posted 8 years ago

Reputation: 1 379

1Is this true for all calculators? I'm sure they do constantly show the decimal point – Beta Decay – 8 years ago

Isn't it 1. instead of 1x? Also this is a quine, which is disallowed by the rules. – Erik the Outgolfer – 8 years ago

No, it's 1=, I messed up. I meant 1x than implicit equals, but I forgot that = is a button. – OldBunny2800 – 8 years ago

It only outputs 1 on both my TI-36 and TI-84 CE. Do these not count as "basic" calculators? – Benjamin Urquhart – 6 years ago

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. – OldBunny2800 – 6 years ago

12

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.

Fatalize

Posted 8 years ago

Reputation: 32 976

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 – 8 years ago

4@MDXF "Usual quine rules don't apply" – Rob Watts – 8 years ago

3@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 – 8 years ago

10

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

Olivier Grégoire

Posted 8 years ago

Reputation: 10 647

2()->1E10-1+"" , "9.999999999E9" (13) saves three more bytes – JollyJoker – 8 years ago

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 – 7 years ago

9

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.

Okx

Posted 8 years ago

Reputation: 15 025

"which is an accepted output method" only for function solutions, not for full programs. – Martin Ender – 8 years ago

@MartinEnder Would those solutions count as functions, then? Not really sure, as I don't often use functions here. – Okx – 8 years ago

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 – 8 years ago

9

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.

James

Posted 8 years ago

Reputation: 54 537

3ii doesn't expand until you press escape, so should that be three or four bytes (or keystrokes, rather)? – algmyr – 8 years ago

@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. – James – 8 years ago

8

Batch, 12 bytes

@echo %OS%

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

Windows_NT

Neil

Posted 8 years ago

Reputation: 95 035

It seems that it's 11 bytes not 12. – Erik the Outgolfer – 8 years ago

@EriktheOutgolfer cmd.exe will of course echo a CRLF after the Windows_NT, thus 12 bytes. – Neil – 8 years ago

Then you should clarify? – Erik the Outgolfer – 8 years ago

8

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.

Martin Ender

Posted 8 years ago

Reputation: 184 808

8

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

steenbergh

Posted 8 years ago

Reputation: 7 772

8

R, 7 bytes

mode(T)

Prints "logical"

Ivanneke

Posted 8 years ago

Reputation: 121

Welcome to PPCG! – Martin Ender – 8 years ago

7

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.

Luis Mendo

Posted 8 years ago

Reputation: 87 464

7

Jelly, 1 byte

V

Quite a few Jelly one byters - this is one - it evaluates the left argument which, when nothing is provided as input, defaults to zero which in turn evaluates to zero and the result is implicitly printed, a 0.

Try it online!

In fact, of the 256 bytes in the code-page there are only 95 that do not currently produce a different one byte output within the specified range when run as a full program; these are (as code-page characters in byte order):

¡¢£¦©½¿€ÇÑÞßçıȷñ÷þ"#&',-./0123456789:;?@IMRTVZ\`dmpstxyz{}~°³⁴⁵⁹ƓƈɠḶỌṬḊĖİĿṄȮṖṘẆẊṃọṣṭḃḟḣŀṁṗṡẋż’“

Notes:

  • Most of the 1-byte programs print a 0 (no-ops / yielding a list with a single zero in, which prints a 0), most others print a 1 (0=0 and the like)

  • is the one program which does yield a different byte, but one which is out of range as per the specification - it produces the null-byte (casts the 0 to character)

  • produces a space (a literal)

  • produces a line feed (a literal)

  • Some bytes that do work now may not do so in the future - there are a fair few bytes being reserved (I believe) for niladic values which, when assigned, are almost certainly not going to produce one-byte output.

Jonathan Allan

Posted 8 years ago

Reputation: 67 804

1Dead link for byte – Weedoze – 8 years ago

7

Charcoal, 2 bytes

→¹

Try it online!

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

ASCII-only

Posted 8 years ago

Reputation: 4 687

Man charcoal's a really nifty language, I should learn it some time – Skidsdev – 8 years ago

7

Cubix, 6 4 bytes

@"Ou

Try it online

Cubified

  @
" O u .
  .

This pushes the string Ou. to the stack, Outputs the top character (.) as a character code (46), does a u-turn to the right, Outputs again, and exits with @.

user48543

Posted 8 years ago

Reputation:

very nice answer, @(Ou works as well – MickyT – 8 years ago

7

Befunge, 2 bytes

.@

Try it online!

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

Martin Ender

Posted 8 years ago

Reputation: 184 808

7

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

milk

Posted 8 years ago

Reputation: 3 043

If you use long you can do it shorter with only one group: ()=>$"{1L<<50}";. Try it online!

– Ørjan Johansen – 8 years ago

Good job on posting such a short C# answer. You can also shave of a byte by using +"" instead of string interpolation. – LiefdeWen – 8 years ago

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 – 8 years ago

2Why do you include a semicolon? It's not part of the function. – LegionMammal978 – 8 years ago

7

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.

Steve Bennett

Posted 8 years ago

Reputation: 1 558

You could also use !!!0, 1e2 or "" – powelles – 8 years ago

7

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 :)]

OpiesDad

Posted 8 years ago

Reputation: 171

1Welcome to PPCG! I edited your header so that it gets picked up by the leaderboard. :) – Martin Ender – 8 years ago

"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 – 8 years ago

@pajonk Great point. I have taken the smaller solution out as I agree it does not meet the conditions. Thanks! – OpiesDad – 8 years ago

7

bash, 48 bytes

bash bash bash bash bash bash! bash! bash! bash!

Output:

/bin/bash: /bin/bash: cannot execute binary file

MD XF

Posted 8 years ago

Reputation: 11 605

6

JavaScript (ES6), 9 bytes

_=>""+1E8

Returns 1 * 10^8, or 100000000.

If I can return a number instead of a string, _=>1E5 is 6 bytes.

f=
_=>""+1E8

console.log(f())

Stephen

Posted 8 years ago

Reputation: 12 293

1Beat me by a couple of minutes. – Steve Bennett – 8 years ago

1Some of the Python answers seem to be outputting numbers, so you should be fine doing the same. – numbermaniac – 8 years ago

1@numbermaniac But they print them, which converts them to string. – Neil – 8 years ago

@numbermaniac OP (Martin Ender) told me it was wrong. – Stephen – 8 years ago

a=b=>b+"" 9 bytes Include the function name :) – Esc Điệp – 5 years ago

6

QBasic 4.5, 1 byte

?

This prints nothing. Followed by a newline.

steenbergh

Posted 8 years ago

Reputation: 7 772

1Thou winneth one internet. – Joshua – 8 years ago

6

Ruby, 5 4 3 bytes

Crossed out 4 is still 4 ;(

p$*

Prints [] (empty array) then a newline

Try it online!

G B

Posted 8 years ago

Reputation: 11 099

Nice. I was about to propose p p, but didn't think about the newline. – Eric Duminil – 8 years ago

6

C (modern Linux), 19 bytes

main(){raise(11);}

Output (with newline):

Segmentation fault 

How it works:

SIGSEGV is defined as 11 in /usr/include/asm-generic/signal.h. Therefore, raise(11) raises SIGSEGV, and when SIGSEGV is raised on Linux, all execution stops and Segmentation fault is printed.

20 bytes

main(){raise(2*2);}

Output (with newline):

Illegal instruction 

22 bytes

main(){raise(2*3-1);}

Output (with newline):

Trace/breakpoint trap

22 bytes

main(){raise(5*2+5);} 

Output (with newline):

User defined signal 1 

22 bytes

main(){raise(1?26:0);}

Output (with newline):

Virtual timer expired 

24 bytes

main(){raise(12*(1+1));}

Output (with newline):

CPU time limit exceeded 

25 bytes

main(){raise(5*5?5*5:0);}

Output (with newline):

File size limit exceeded 

25 bytes

main(){printf(raise(8));}

Output (with newline):

Floating point exception 

MD XF

Posted 8 years ago

Reputation: 11 605

1isn't that first one 18 bytes? – Destructible Lemon – 8 years ago

@DestructibleLemon Nope. There's a newline at the end. – MD XF – 8 years ago

1why isn't the second one 20 bytes then? – Destructible Lemon – 8 years ago

@DestructibleLemon Because..... oops. Will fix tomorrow morning. – MD XF – 8 years ago

2To be pedantic, all of these messages are written by the shell that launched your program, not by your program itself. – Anders Kaseorg – 8 years ago

@AndersKaseorg C (modern linux), the messages are generated by the Linux kernel. – MD XF – 8 years ago

I get extraneous messages on my pi, cygwin, and my linux boot.. – tuskiomi – 8 years ago

@tuskiomi for which? – MD XF – 8 years ago

the 19 byte. I'm not saying your answer is invalid, maybe put some more specificity into it. – tuskiomi – 8 years ago

2

@MDXF It really is the shell, not the kernel. You can prove it by running echo 'main(){raise(11);}' | gcc -xc -; echo ./a.out | strace bash, which shows bash making the write call. The exact format varies from shell to shell. Here is where the message is defined within the bash source code. You will not find it anywhere in the Linux kernel outside of documentation.

– Anders Kaseorg – 8 years ago

5

><>, 4 bytes

"on;

Try it online!

Outputs ;110

Emigna

Posted 8 years ago

Reputation: 50 798

5

Python 3, 53 bytes

s='s=%r;print("0"*~-len(s%%s))';print("0"*~-len(s%s))

Try it online!

This must be the most quine-like answer ever.

Leaky Nun

Posted 8 years ago

Reputation: 45 011

1Why not print(1e6)? – CalculatorFeline – 8 years ago

@CalculatorFeline that would be un-quine-like. – Leaky Nun – 8 years ago

Your answer should not be a quine. – Notts90 supports Monica – 8 years ago

@Notts90 this isn't a quine. – Leaky Nun – 8 years ago

5

Alice, 5 bytes

g/@O

Try it online!

Prints:

103
g

Explanation

This was quite fun to figure out. :)

g   Pop two implicit zeros from the stack and retrieve the code point at that
    location in the code. That's the 'g' itself, so we're pushing 103.
/   Reflect to SE. Switch to Ordinal. The IP bounces diagonally up and down
    through the code.
O   Implicitly convert the 103 to "103" and print it with a trailing linefeed.
    Bounce off the top right corner and move back.
/   Reflect to W/ Switch to Cardinal.
g   Push 103 again.
    The IP wraps back to the last column
O   Interpret the 103 as a code point and print the corresponding character.
    This prints 'g'.   
@   Terminate the program.

Martin Ender

Posted 8 years ago

Reputation: 184 808

5

APL, 2 bytes

-1

Prints ¯1 (the - is the Minus monad, whereas ¯ is the High minus negative indicator).

Uriel

Posted 8 years ago

Reputation: 11 708

5

Perl 5, 9 bytes

print$"x9

Prints 9 spaces, no newline.

Explanation

$" contains a " " by default. x9 uses the repetition operator to "multiply" the string by 9.

jhx4mp

Posted 8 years ago

Reputation: 51

1Welcome to PPCG! – Martin Ender – 8 years ago

5

Powershell, 38 bytes

Just for fun, an answer that returns different output each time it's called.

[System.Guid]::NewGuid().ToString("B")

Prints a GUID surrounded with braces ("B"), such as:

{24cc14a3-ada4-4fcd-8a08-ec419b00f22d}

Danko Durbić

Posted 8 years ago

Reputation: 10 241

5

R, 3 2 bytes

-T

Outputs:

-1

Old 3 byte answers:

Many examples, such as:

1/0
F/F
3^6

Outputs respectively:

Inf
NaN
729

Try it online!

ngm

Posted 8 years ago

Reputation: 3 974

hah, -T! clever! – Giuseppe – 7 years ago

4

Python 2, 10 bytes

Try it online

print 9**9

Outputs 10 bytes:

387420489
*newline*

There are other 10-byte answers with decimals and power. I like this one for e in the output:

print.3**8

Output:

6.561e-05
*newline*

Same 10 bytes, but for division (there are 5 versions):

.1/64 = 0.0015625
.3/64 = 0.0046875
.5/64 = 0.0078125
.7/64 = 0.0109375
.9/64 = 0.0140625


print.1/64

outputs:

0.0015625
*newline*

Dead Possum

Posted 8 years ago

Reputation: 3 256

1Also works in Cheddar – Leaky Nun – 8 years ago

2@LeakyNun Why don't you post it as answer? – Dead Possum – 8 years ago

4

JavaScript (ES6), 17 11 bytes

f=_=>"g="+f

Try it

f=_=>"g="+f
console.log("Function source: f="+f)
console.log("Function length: "+(""+f).length+" + 2 (for variable assignment) = "+((""+f).length+2))
console.log("Function output: "+f())
console.log("Output length: "+f().length)
console.log("Output type: "+typeof f())

Shaggy

Posted 8 years ago

Reputation: 24 623

4

Fourier, 1 byte

o

Try it FourIDE!

Note, TIO.run outputs a trailing newline

Outputs the value of the accumulator, 0.

More interesting programs:

2P15o

Try it on FourIDE!

Outputs 215, 32768.


4^do

Try it on FourIDE!

Outputs the current year (doesn't work if used before 1000 AD).


999**999o

Try it on FourIDE!

Outputs 997002999. The ** is undefined behaviour in Fourier. The way I think it works is A**B = A*A*B.

Beta Decay

Posted 8 years ago

Reputation: 21 478

4

Bash, 1 byte:

#

It sort of outputs a newline...although I don't know if the program gets credit for that or the Bash interpreter.

I'm a bit dubious that this counts, so:

Bash, 21 bytes

x=12345;echo $x$x$x$x

This is really terrible, I know. Are you allowed to call any standard program with Bash?

Steve Bennett

Posted 8 years ago

Reputation: 1 558

1https://codegolf.meta.stackexchange.com/a/7833/56341 languages are denfined by their implementation rather than by their declaration. so your 1 byte solution is perfectly valid – Roman Gräf – 8 years ago

Ok. I'm still not sure. Calling almost anything from a bash shell will generate a new line, it's not even the interpreter that's looking at my program that does that (I think). It's just that after doing whatever my program does (which is nothing), the Bash shell (which is essentially a REPL) outputs a blank line. – Steve Bennett – 8 years ago

4It doesn't output anything. What version of Bash are you using? – eush77 – 8 years ago

Heh, see my comment, right? – Steve Bennett – 8 years ago

x=12345;echo $x$x$x$x only outputs 20 characters for a 21 character input. Try x=1234567;echo $x$x$x also 21 characters, 21 characters output (123456712345671234567) - oh wait, do we count the implicit \n? does that count as a feature of the program or the shell displaying output? – Baldrickk – 8 years ago

yeah, that was basically my question. – Steve Bennett – 8 years ago

Run that piped to wc -c and you find it doesn't output anything at all. – Joshua – 8 years ago

Yes, I believe @eush77 made that observation already. – Steve Bennett – 8 years ago

4

Java, 82 bytes

interface M{static void main(String[]a){for(int i=0;i++<82;)System.out.print(1);}}

Output:

1111111111111111111111111111111111111111111111111111111111111111111111111111111111

Try it online!

Leaky Nun

Posted 8 years ago

Reputation: 45 011

1Why not a lambda? I admit that it is boring, but I think it could be included to showcase Java 8. – Yytsi – 8 years ago

1

@TuukkaX I made one!

– Olivier Grégoire – 8 years ago

4

C#, 23 bytes

()=>new string('@',23);

Creates a new string consisting of 23 @ characters

LiefdeWen

Posted 8 years ago

Reputation: 3 381

4

dc, 2 bytes

Kp

Try it online!

Pushes the current precision on the stack (which is 0) and prints it with a trailing newline.

Maxim Mikhaylov

Posted 8 years ago

Reputation: 571

dc prints a trailing newline after any command. The command 'c' has no other output, so it works and is one byte shorter – Jared K – 7 years ago

4

GNU Make, 24 21 bytes

$(sort $(value $(0)))

returns

$(0))) $(sort $(value

Complete makefile:

X=$(sort $(value $(0)))
$(info $(call X))

eush77

Posted 8 years ago

Reputation: 1 280

How do you invoke this? For me if I put this in a Makefile and run make, I get make: *** No targets. Stop. – Digital Trauma – 8 years ago

@DigitalTrauma It's a user-defined function. I added the boilerplate to the post.

– eush77 – 8 years ago

Very impressive! +1 – MD XF – 8 years ago

4

Pyth, 1 byte

k

It prints a new line character.

Explanation: k is just a variable initialized to '' (empty string), and by default Pyth prints the values of instructions which do nothing, followed by a new line character. In this case, it prints an empty string and then the new line character.

Test it online! (the online interpreter doesn't show the \n, you will have to install Pyth on your computer to actually see it)

Jim

Posted 8 years ago

Reputation: 1 442

4

Underload, 6 bytes

()aaaS

Try it online!

Prints ((())).

() pushes an empty string to the stack. a "stringifies" it by wrapping it in (...) so after aaa we get (((()))). S prints that string (without the outermost parentheses, so we get only three pairs).

Martin Ender

Posted 8 years ago

Reputation: 184 808

4

Taxi, 540 bytes.

62 is waiting at Starchild Numerology.Go to Starchild Numerology:w 1 l 2 r 1 l 1 l 2 l.Pickup a passenger going to The Underground.Go to The Underground:w 1 r 2 r 1 r 2 l.[r]Switch to plan "e" if no one is waiting.Pickup a passenger going to Cyclone.Go to Cyclone:n 3 l 2 l.Pickup a passenger going to The Babelfishery.Pickup a passenger going to The Underground.Go to The Babelfishery:s 1 l 2 r 1 r.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.Go to Fueler Up:n 1 r 1 l.Go to The Underground:n.Switch to plan "r".[e]

Try it online!

Ungolfed:

62 is waiting at Starchild Numerology.
Go to Starchild Numerology: west 1st left 2nd right 1st left 1st left 2nd left.
Pickup a passenger going to The Underground.
Go to The Underground: west 1st right 2nd right 1st right 2nd left.
[r]
Switch to plan "e" if no one is waiting.
Pickup a passenger going to Cyclone.
Go to Cyclone: north 3rd left 2nd left.
Pickup a passenger going to The Babelfishery.
Pickup a passenger going to The Underground.
Go to The Babelfishery: south 1st left 2nd right 1st right.
Pickup a passenger going to Post Office.
Go to Post Office: north 1st left 1st right.
Go to Fueler Up: north 1st right 1st left.
Go to The Underground: north.
Switch to plan "r".
[e]

It prints the integers 61 through 1 in descending order and with a decimal and 6 trailing zeros:

61.00000060.00000059.00000058.00000057.00000056.00000055.00000054.00000053.00000052.00000051.00000050.00000049.00000048.00000047.00000046.00000045.00000044.00000043.00000042.00000041.00000040.00000039.00000038.00000037.00000036.00000035.00000034.00000033.00000032.00000031.00000030.00000029.00000028.00000027.00000026.00000025.00000024.00000023.00000022.00000021.00000020.00000019.00000018.00000017.00000016.00000015.00000014.00000013.00000012.00000011.00000010.0000009.0000008.0000007.0000006.0000005.0000004.0000003.0000002.0000001.000000

Engineer Toast

Posted 8 years ago

Reputation: 5 769

4

PowerShell, 2 bytes

+1

The upvote program. This give the output of 1 and a trailing newline to get 2 bytes. I am unsure if the operation is adding 1 to nothing or if it is rendering the positive integer of 1. Either way the result is the same.

Matt

Posted 8 years ago

Reputation: 1 075

4

Pyramid Scheme, 32 bytes

^ ^ 
-^-
^-^
-^-
^-^
-^-
^-^
- -

Try it online!

Explanation

This may not look like pyramid scheme but it is. Each triangle looks like:

 ^
 -

This performs one of three operations

  • If it has 2 args it pairs them together

  • If it has 1 arg it returns it

  • If it has 0 args it returns 0

So at the bottom we have two zeros, those are linked on the next level. On the next level two different pyramids grab the pair and then those pairs are paired together. This continues all the way up the pyramid. When we get to the top we have:

 ((((0,0),(0,0)),((0,0),(0,0))),(((0,0),(0,0)),((0,0),(0,0))))

Pyramid scheme's implicit output converts this to 16 zeros separated by newlines. That's 32 bytes.

Post Rock Garf Hunter

Posted 8 years ago

Reputation: 55 382

3

TAESGL, 1 byte

S

Interpreter

Outputs a single space character

Other solutions

"≠        2 bytes, "≠" converted to "!="
«Ā»       3 bytes, decompresses "Ā" which is equal to "the"
SŔ4)      4 bytes, " " repeated 4 times
5ē)ĴT     5 bytes, first 5 Fibonacci numbers joined
G→6,"A    6 bytes, draws a line to the right of "A" for 6 characters

Tom

Posted 8 years ago

Reputation: 3 078

3

PHP, 216 68 7 bytes

<?=1e6;

Try it online!

Thanks to Jörg I'm beating Okx again :D

Skidsdev

Posted 8 years ago

Reputation: 9 656

3<?=1e6; 7 Bytes – Jörg Hülsermann – 8 years ago

3

Powershell, 3 bytes

1E2

Prints 100

Danko Durbić

Posted 8 years ago

Reputation: 10 241

Looks like you (hopefully accidentally) added a leading space to your code. – Skidsdev – 8 years ago

PowerShell adds a trailing newline. Newlines count for this one. 1e1 would work though – Matt – 8 years ago

3

Stack Cats, 1 + 3 = 4 bytes

+

Try it online!

Requires either the -o or -n flag for numeric output. Prints two zeros, with a linefeed each.

Explanation

Stack Cats has a tape of stacks which are all initialised to an infinite wells of zeros, but the starting stack has a -1 on top (which acts as a terminator when input is given). The + command swaps the first and third element on the current stack. So:

-1           0
 0           0
 0     +    -1
 0   ---->   0
 .           .
 .           .
 .           .

At the end of the program, the current stack is printed from top to bottom. Since the -1 is again treated as a terminator, it's not printed itself. Due to the -o flag, the values are printed as decimal integers with trailing linefeeds.

Martin Ender

Posted 8 years ago

Reputation: 184 808

3

Octave, 7 bytes

[['']]'

Try it online!

Luis Mendo

Posted 8 years ago

Reputation: 87 464

3

TI-Basic (TI-84 Plus CE OS 5.2+), 4 bytes

toString(10^(3

tostring( is a two-byte token, 10^( is a one-byte token. This returns the string "1000" which is 4 bytes long.

pizzapants184

Posted 8 years ago

Reputation: 3 174

@Scrooble toString( is a two byte token, so the output does need to be 4 bytes, not 3, even though it has 3 tokens – pizzapants184 – 7 years ago

I know. I probably shouldn't post anything at 12:30 AM to avoid embarrassment. I was too slow to recall my comment before you saw it. – Khuldraeseth na'Barya – 7 years ago

3

Fission, 4 bytes

R"N;

Try it online!

Prints N;R with a trailing linefeed.

The R creates a right-going atom. " toggles string mode which traverses an immediately prints N;R (wrapping at the end of the line). Then N prints a linefeed and ; destroys the atom, terminating the program.

Martin Ender

Posted 8 years ago

Reputation: 184 808

3

AWK, 21 bytes

BEGIN{printf"%21s",0}

Try it online!

Simply prints:

                    0

The 0 could of course be any digit. No new line is printed, since that would add 2 bytes.

Robert Benson

Posted 8 years ago

Reputation: 1 339

3

OCaml, 22 bytes

List.find ((=) "") []

Outputs

Exception: Not_found.

It search for "" (empty string) in the empty list []

juloo65

Posted 8 years ago

Reputation: 81

Welcome to PPCG! It seems this prints a trailing linefeed, so the output is actually 23 bytes. (I don't know OCaml but I imagine the easiest fix would be to pad the code with another space, or add a trailing linefeed to it as well.) – Martin Ender – 8 years ago

Hi, the output is 22 bytes when counting the newline ! However, for the code, I added the trailing newline to the count – juloo65 – 8 years ago

1Ah okay, should have counted the bytes then. It might be good if you mentioned that both code and output include the linefeed. – Martin Ender – 8 years ago

3

Ruby, 3 bytes

p""

Prints this, plus a newline

""

Here's another 3 byte one:

p:a

Prints this, plus a newline

:a

addison

Posted 8 years ago

Reputation: 993

3

R, 7 bytes

stop( )

Prints Error: (with a trailing space)


16 bytes (only works in version 3.3.1)

version$nickname

Prints Bug in Your Hair.

Not nearly as good but I like it anyway.

user2390246

Posted 8 years ago

Reputation: 1 391

3

charcoal, 1

Try it online!

Explanation:

⎚ Clears the empty screen
[implicitly print nothing plus a trailing newline]

Destructible Lemon

Posted 8 years ago

Reputation: 5 908

What is that character supposed to be? Is it an old CRT TV screen? – Beta Decay – 8 years ago

searching it comes up with the wikipedia article for clear, like in bash – Destructible Lemon – 8 years ago

3

><>, 11 bytes

01+:b=?;:n!

Prints numbers from 1-10 (12345678910)

AGourd

Posted 8 years ago

Reputation: 271

Nope. Maybe because there's a bounty on it? One of only three featured questions. – AGourd – 8 years ago

Maybe. Still, not many people are constantly looking at the fifth page. Then again, maybe the OP and bounty-watchers... – MD XF – 8 years ago

Well, I don't really know what to tell you. I'm as surprised as you honestly. – AGourd – 8 years ago

I was pretty surprised when my 19-byte solution to this challenge got 100+ votes. And it only took 30 seconds to write... – MD XF – 8 years ago

3

Mathematica, 2 bytes

Code:

.0

Output:

0.

This is the output of Wolfram kernel from command line, and the plaintext output from the front end. If you must argue about the extra number tick added when copying directly from the front end, then 0.0 will do.

happy fish

Posted 8 years ago

Reputation: 131

3

Whitespace, 36 bytes

  	 				



 	
 	   	
	    

		

Try it online!

Generates the output "-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1" (36 characters without quotes, no trailing newline)

Explanation

Pushes the number -15 onto the stack (encoded in binary as 01111, with a leading 0 for padding to match the output) then counts toward 0 outputting the current number each iteration.

Starting from a negative number gives an extra byte of output per iteration and also allows me to use a jump while negative instruction to fall through the loop and exit implicitly. That single padding byte in the code is a downer though but solutions without it are longer.

Ephphatha

Posted 8 years ago

Reputation: 581

3

Python 3, 13 bytes

print("a"*13)

Outputs "aaaaaaaaaaaaa"

user69864

Posted 8 years ago

Reputation:

2

Python 2, 11 bytes

print 4**16

Beep boop.

Yytsi

Posted 8 years ago

Reputation: 3 582

1You can do 8**9 for 10 bytes. – PurkkaKoodari – 8 years ago

1@Pietu1998 I was about to do 9**9, but @DeadPossum ninja'd me, so I'd rather keep this... – Yytsi – 8 years ago

2

Cjam, 1 byte

N

Explanation

N e#Push '\n' and implicit print

Roman Gräf

Posted 8 years ago

Reputation: 2 915

2

JavaScript (ES6), 17 bytes

Edit: I overlooked the rules. This is now returning a string, but is much longer than initially intended.

Returns "Infinity,Infinity".

let f =

_=>`${[1/0,1/0]}`

console.log(f())

Arnauld

Posted 8 years ago

Reputation: 111 334

2

QBIC, 8 2 bytes

?z

Prints 10, to which z is auto-initialised.


Original brainfart answer

?A+@1234

Explanation:

?       PRINT
A+      A$ (which is undefined, but hold on!), plus
@1234   The string literal 1234, which we now call A$

Outputs 12341234, which is also 8 bytes. We save a byte by putting the string lit at EOF, because we now don't need to use the delimiter. The definition of the literal is moved to the top of the QBasic code by the interpreter, ensuring it existst at the moment of the first call to A$.

steenbergh

Posted 8 years ago

Reputation: 7 772

2

C#, 57 49 47 44 bytes

()=>{for(int i=0;i<44;i++)Console.Write(7);}

-8 bytes thanks to Martin

Not 100% on whether lambdas like this are accepted answers, but my previous submission in this format was accepted just fine, so I'm gunna go with it.

Same as the java answer, but better because it's not Java

Skidsdev

Posted 8 years ago

Reputation: 9 656

2

J, 6 bytes

echo!4

Try it online!

Output:

24
   

Notice the three spaces on the second line.

Leaky Nun

Posted 8 years ago

Reputation: 45 011

2

Deadfish, 1 byte

o

Outputs the accumulator, which is 0 before any action takes place.

note: deadfish prints the accumulator as a number, not as a character code, so the output is "0" (0x48)

Uriel

Posted 8 years ago

Reputation: 11 708

2

SQLite, 32 bytes

.width 31
.mode column
SELECT"";

Try it online!

Outputs 31 spaces and a newline.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

2

Brain-Flak, 12 bytes

(((([()]))))

Try it online!

This prints

-1
-1
-1
-1

Post Rock Garf Hunter

Posted 8 years ago

Reputation: 55 382

This seems to be 11 bytes of output, not 12. – James – 8 years ago

@DJMcMayhem You're right, fixed – Post Rock Garf Hunter – 8 years ago

It's to bad -v print Brain-Flak Ruby Interpreter v1.4.2 instead of just v1.4.2. – Riley – 8 years ago

2

Klein, 7 5 + 3 bytes

Uses the 110 topology

1.
2@

If we unfold the topology here we get

1.122@

This outputs 1 1 2 2 with a trailing newline.

Thanks to Martin Ender for saving two bytes!

Post Rock Garf Hunter

Posted 8 years ago

Reputation: 55 382

2

Somme, 2 bytes

:.

Try it online!

Outputs 42. Explanation:

:.
:    duplicate; no input, so popping from an empty stack pushes `42`
 .   output as a number

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

1popping from an empty stack pushes 42 ಠ_ಠ – MD XF – 7 years ago

2

Stacked, 9 bytes

$put:+put

Try it online!

Outputs [put put]. $put pushes a function literal to the stack, : duplicates it, + concats the two functions, and put outputs the representation of the top of the stack.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

2

Haskell, 16 bytes

main=print[0..6]

Try it online! Output:

[0,1,2,3,4,5,6]

(Note the trailing newline.)

Laikoni

Posted 8 years ago

Reputation: 23 676

2

MSM, 8 bytes

'.;;.;.;

Output:

........

MSM operates on its own source and takes commands from the left and treats the right as a stack. Stack trace:

' . ; ; . ; . ;                  # ' pushes the next char on the stack
    ; ; . ; . ; .                # ; is dup
      ; . ; . ; . .              # dup again
        . ; . ; . . .            # . is concat
          ; . ; . ..             # dup 
            . ; . .. ..          # concat
              ; . ....           # dup
                . .... ....      # concat
                  ........       # MSM stops if there's only one element in the stack

nimi

Posted 8 years ago

Reputation: 34 639

2

Python 3 REPL, 3 bytes

1e0

Prints 1.0.

If trailing newline counts,

5*2

Prints 10, then a trailing newline.

OldBunny2800

Posted 8 years ago

Reputation: 1 379

1Yes, the trailing linefeed counts. – Martin Ender – 8 years ago

2

Bash + coreutils (on 32-bit Linux), 5 bytes

arch
(trailing newline)

Prints

i686
(trailing newline)

Old solution:

sed s/e/a $0

Save (without trailing newline) in filename, and run with bash filename.

Prints

sad s/e/a $0

with no newline. Really you could replace any character in the file with a different character, but s/e/a/ makes the output sad. :(


Other solution (10 bytes):

sort $0
a=

(no trailing newline)

Prints:

a=
sort $0

pizzapants184

Posted 8 years ago

Reputation: 3 174

1Ah, that's really nice. – Steve Bennett – 8 years ago

2

TacO, 1 byte

@

Outputs a single newline.

Taco's default behaviour is to print out a newline, for some reason. But, the code needs an entry point, @, to work. So this works.

Try it online!

ATaco

Posted 8 years ago

Reputation: 7 898

2

Japt, 1 byte

Outputs a string containing a single ".

Q

Try it online


Or this will output a string containing a single \n.

R

Try it online

Shaggy

Posted 8 years ago

Reputation: 24 623

Heh, nice. S will work too, or T, or U, or a, or f, or... there are probably 40 or so options that print 0 or 1. – ETHproductions – 8 years ago

@ETHproductions, T, U, a, f, etc. wouldn't be valid as string output is required. s works, though. – Shaggy – 8 years ago

Only functions are required to return strings. The output of any program is considered a string by default, since there's no way to tell between outputting "123" vs. 123 (both just show up as 123) – ETHproductions – 8 years ago

Unless, in the case of Japt, you use the -Q flag ;) But that's good to know, thanks @ETHproductions. – Shaggy – 8 years ago

2

7, 3 characters, 1 byte

Seen as individual characters:

723

Or as a hex dump, proving that it runs from a file that's one byte long:

00000000: e9                                       .

Try it online!

Outputs the characters 23 in 7's encoding. This also happens to be a single byte long, and a printable ASCII byte at that:

00000000: 4f                                       O

Explanation

This is a literal that pushes two stack elements: an empty stack element (7 separates stack elements), and 23, 7's print statement. When the end of the program is reached, the top stack element is copied and evalled, meaning that an attempt is made to print 23; because this contains characters that don't exist in 7's encoding (the active versions of the 2 and 3 commands, shown in bold in the explanation), the printed value gets escaped (into 723), and the 7 is interpreted as a request to format the output in the same encoding as the input, with the 23 getting printed.

It can be observed that the leading 7 on the program is entirely pointless, except to make the output and input distinct.

user62131

Posted 8 years ago

Reputation:

2

Perl, 8 7 bytes

print$␖

The seventh byte of this program is the control character \x16, which I can't put literally into the writeup. A hexdump of the source is 70 72 69 6e 74 24 16.

Output is something like v5.20.2 on the standard output. The exact output depends on the exact version, but almost always 7 characters in practical situations. There is no newline or whitespace in the source code or output.

Note that running this code also prints a long mandatory warning message to the standard error. If I understand correctly, that message is ignored by the golf rules.


One byte longer (but all printable) is this program:

;print**

The semicolon is there to pad the code to the same length as the output. The output is *main::*

b_jonas

Posted 8 years ago

Reputation: 341

2

Carrot, 4 bytes

.^*3

Prints .... (4 .s).

Try it online!

Explanation

.^                        Sets the stack-string to "."
  *3                      Append three duplicates of the stack-string to itself
                          Implicit output

user41805

Posted 8 years ago

Reputation: 16 320

2

Ruby, 16 bytes

puts (1..8).to_a

returns

1
2
3
4
5
6
7
8

Can I use this to enter challenge?
Try it Online!

Zaw Hlaing Bwar

Posted 8 years ago

Reputation: 29

1Looks good to me. Welcome to PPCG! :) – Martin Ender – 8 years ago

p (1..4).to_a should work, for 13 bytes. – Dennis – 8 years ago

@Dennis and https://codegolf.stackexchange.com/a/121108/6691 is even shorter and already posted, so what's the point of that comment?

– b_jonas – 8 years ago

@b_jonas Just because someone achieved a better score doesn't mean you can't try to get the most of your approach. – Dennis – 8 years ago

2

ZX Spectrum BASIC, 1 byte

PRINT

(which is 1 byte) prints a single newline.

Radovan Garabík

Posted 8 years ago

Reputation: 437

I think Apple][ integer Basic does a similar thing with ? for PRINT – roblogic – 6 years ago

2

dc (bash command line under Linux), 9 bytes

(inc newlines on both the math expression and the answer)

2 24 ^ p

Prints:

16777216

I wanted to make sure RPN wasn't forgotten about :)

Wossname

Posted 8 years ago

Reputation: 221

Welcome to PPCG! You're a little bit outgolfed already.

– Ørjan Johansen – 8 years ago

@ØrjanJohansen, hehe yes I don't mind, to be honest I just wanted to play along. The day that P8x32A Assembly language is a valid language around here I'll whup everyone :D – Wossname – 8 years ago

You're free to use any language you want (as long as there's a working implementation), including P8x32A assembly. – Dennis – 8 years ago

@Dennis, define "working". I doubt many PCG frequenters would feel like grabbing a soldering iron and building a circuit to prove that the code works :) – Wossname – 8 years ago

1So basically it needs an emulator. – Ørjan Johansen – 8 years ago

@ØrjanJohansen, as far as I'm aware there isn't a pure-software emulator for it. I've tinkered with the idea of writing one over the years but I've failed to get anyone else interested in such a thing. Would be a neat summer project though. Hmm. – Wossname – 8 years ago

2

Microscript, 1 byte

E

Prints 100=1. e will also work, printing 20=1.

SuperJedi224

Posted 8 years ago

Reputation: 11 342

2

Forth (gforth), 4 bytes

.S \

Prints <0> (that's <, 0, >, and space). Stack must be empty (for example if gforth was just started)

How it works: .S prints the stack depth enclosed in brackets and then the stack contents seperated with a space. \ is the beginning of a comment, it does nothing.

Forth (gforth), 8 bytes

8 SPACES

Well, it prints 8 spaces. Not much to see here.

2xsaiko

Posted 8 years ago

Reputation: 699

2

SmileBASIC 3, 3 bytes

?@A

Prints the string @A, plus a trailing newline, so output is 3 bytes.

snail_

Posted 8 years ago

Reputation: 1 982

2

MarioLANG, 1 byte

:

Output the numeric value from current memory cell, which is 0

user69335

Posted 8 years ago

Reputation:

2

TI-Basic, 7 bytes

(Ab)using the fact that Done is displayed when nothing is evaluated on the last line. Lowercase letters are two bytes each in TI-Basic.

Repeat 1337:End

Timtech

Posted 8 years ago

Reputation: 12 038

I wouldn't count printed lowercase letters as two bytes. Lowercase letter tokens take two bytes to store, but I think the calculator doesn't store the tokens when it prints the letters. – lirtosiast – 8 years ago

@lirtosiast You could always have something like Repeat 1:End for 4 bytes of course. – Timtech – 8 years ago

Yes, that would be better – lirtosiast – 8 years ago

2

HQ9+, 13 bytes

haaaaaaaaaaaa

Prints:

Hello, world!

The instruction "h" in HQ9+ will print "Hello, world!" and any instruction that is not "h" "q" "9" or "+" will be ignored.

You might want to know why this language exists, and why I'm answering this question with it.

Why not?

LyricLy

Posted 8 years ago

Reputation: 3 313

2

VBA, 1 Byte

A surprisingly short answer for VBA

Anonymous VBE immediate window function that takes no input and outputs a single linefeed (vbLf) to the immediate window

?

Output


(A single linefeed)

Taylor Scott

Posted 8 years ago

Reputation: 6 709

2

Python 3 REPL, 11 bytes

str(...)[:]

Try it online! The header and the footer emulate a REPL.

This prints:

'Ellipsis'

totallyhuman

Posted 8 years ago

Reputation: 15 378

2

><>, 3 bytes

"nh

Try It Online

Prints "104" and exits with an error.

Jo King

Posted 8 years ago

Reputation: 38 234

2

Stax, 1 byte

æ

Run and debug online!

Bytes counted in CP437.

Just the packed version of the program 1. Not surprisingly the output is also 1. Since it is packed it is not a quine and is a valid answer.

Weijun Zhou

Posted 8 years ago

Reputation: 3 396

2

R, 25 bytes

sprintf("%.23f",runif(1))

Try it online!

Outputs (as a string) a random number between 0 and 1 with 23 decimal places, e.g.

0.84327139146625995635986

This is 25 characters overall, counting the initial 0.

There are shorter R solutions, but I wanted to post one with randomness since the challenge allows it explicitly.

Robin Ryder

Posted 8 years ago

Reputation: 6 625

At least on TIO this produces output of different length. Caught both 17 (0.703815360320732) and 19 (0.01503348327241838). – manatwork – 6 years ago

@manatwork Thanks! This new version should work consistently. – Robin Ryder – 6 years ago

2

brainfuck, 15 32 bytes

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

Try it online!

Illegal version (no ascii), 15 bytes

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

Try it online!

Dorian

Posted 8 years ago

Reputation: 1 521

Oh, I didn't have in mind that ascii is only up to character 0x7e and not 0xff. I made a new version. – Dorian – 6 years ago

2

Zsh, 5 bytes

<<<$-

Prints 569X followed by a newline. Try it online!

The parameter $- outputs the current flags supplied to the shell. By default, it is set to 569X:

  • 5: NOTIFY
  • 6: BG_NICE
  • 9: AUTO_LIST
  • X: LIST_TYPES

When unsetting these options, $- is empty.

GammaFunction

Posted 8 years ago

Reputation: 2 838

2

Dash/Bash/ksh/fish, 5 bytes

umask

Try it online (Dash) | Try it online (Bash) | Try it online (Ksh) | Try it online (Fish)

umask is a builtin in most unix shells, not an external command! It prints the 4-octal-digit umask followed by a newline for a total of 5 bytes. Does not work in Zsh or Tcsh: Zsh will only print one leading zero (e.g.: 02 instead of 0002), and Tcsh will print no leading zeroes (2 instead of 0002)

GammaFunction

Posted 8 years ago

Reputation: 2 838

2

C#, 84 bytes

public class P{public static void Main(){System.Console.Write(new string('_',84));}}

Try Online

canttalkjustcode

Posted 8 years ago

Reputation: 131

1

Could you get rid of the space and change the number to an 84? (https://dotnetfiddle.net/jgigU2)

– Post Rock Garf Hunter – 6 years ago

1

Braingolf, 1 byte

l

Try it online!

Prints 0 (the current length of the stack)

Braingolf, 2 byte

4*

Prints 16. 4 can be replaced by any number n where 3 < n < 10

Explanation:

4*
4   Pushes 4 to the stack
 *  Monadic multiplication, squares the last item on the stack
    Implicit output of the last item on the stack

Skidsdev

Posted 8 years ago

Reputation: 9 656

@LuisMendo That's the correct link. TIO doesn't have Braingolf yet, but the interpreter is written in Python3, which TIO does have. The code is the 2nd argument. – Skidsdev – 8 years ago

1Don't you think you should explain that in your answer then? – Luis Mendo – 8 years ago

Doesn't the first solution print a trailing newline? – totallyhuman – 8 years ago

1

PHP, 17 bytes

<?php echo 9**17;

Because I wanted to beat Mayube's answer ;)

Try it online!

Okx

Posted 8 years ago

Reputation: 15 025

Touche. I'll get you next time ;) – Skidsdev – 8 years ago

Looks like I got you, kind of :D – Skidsdev – 8 years ago

1same way golfed <?=9**8; – Jörg Hülsermann – 8 years ago

Sorry can't beat Mayube/Jörg's byte count but at least I can give a good and creative tip: <?=1/64;. – Christoph – 8 years ago

1

Go, 60 bytes

I don't know if this is hard in Go or if I'm failing to see something obvious.

import(."fmt"
."strings")
func main(){Print(Repeat("a",60))}

Try it online!

totallyhuman

Posted 8 years ago

Reputation: 15 378

Can you do something like 1e30 or 10^49? – CalculatorFeline – 8 years ago

@CalculatorFeline 1e30 would print 1e+37 and 10^49 would print 37 (due to bitwise operation). – totallyhuman – 8 years ago

1

brainfuck, 33 bytes

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

Try it online!

Output:

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

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

Leaky Nun

Posted 8 years ago

Reputation: 45 011

1Then do it in 32 bytes. – CalculatorFeline – 8 years ago

You should do it in 32 bytes or else it isn't a serious competing entry. – Erik the Outgolfer – 8 years ago

1

brainfuck, 30 bytes

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

Outputs 30 #s.

Try it online!

Business Cat

Posted 8 years ago

Reputation: 8 927

1

Brain-Flak, 32 bytes

(((()()()){}){}()){(({})[()])}()

Try it online!

Prints:

0
1
2
3
...
13

Explanation:

# Push 13
(((()()()){}){}())

# While TOS != 0
{

   # Push TOS, TOS - 1
   (({})[()])

# End While and pad with 2 bytes
}()

Riley

Posted 8 years ago

Reputation: 11 345

Here's my Brain-flak answer btw – Post Rock Garf Hunter – 8 years ago

1

Bash, 11 bytes

printf %11s

prints:

"           "

(without the quotes)

If the newline counts, then printf "%10s" will print 10 characters plus the newline.

I did consider echo $0 (7) which works when saved with a filename 7 characters long, but I think that falls under the common set of unaccepted answers

Baldrickk

Posted 8 years ago

Reputation: 311

2printf %11s outputs exactly 11 spaces – Digital Trauma – 8 years ago

1

Perl 6, 4 bytes

{?1}

Try it

Returns True

Explanation

&prefix:« ? » is a Bool conversion operator

{ and } can be used to create a bare block lambda.

Brad Gilbert b2gills

Posted 8 years ago

Reputation: 12 713

1

Actually, 1 byte

ε

Try it online!

Prints the empty string (and a trailing newline).

Leaky Nun

Posted 8 years ago

Reputation: 45 011

" would also work, as would . – Mego – 8 years ago

1

S.I.L.O.S, 28 bytes

i=28
lblb
i-1
print a
if i b

Try it online!

Output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaa

Leaky Nun

Posted 8 years ago

Reputation: 45 011

1

VBA Immediate Window, 9, 2 bytes

?,

Prints a tab followed by a newline according to this answer in meta

Old answer

?space(6)

Entered in the immediate window, space(n) repeats the space character n times, ? is short for Print & Debug. is implicitly prepended in the immediate window. Printing also gives a space after the function and 2 newlines so only 6 spaces needed

Greedo

Posted 8 years ago

Reputation: 267

Nice job! Golfing down to 22% of original code in one step is pretty impressive. – MD XF – 8 years ago

1

Excel, 13 (12/11) bytes

=TEXT(9^13,0)

Genetrate a number, convert to text, simple!

Alternatively: =1=1 evaluates to TRUE (4bytes)

TRUE is boolean not text

Update

Very debateably for 12 and 11 bytes respectively

=TEXT(9^12,0

Leaving off the close bracket evaluates without a fuss

=REPT("a,11

Leaving out a bracket and " still evaluates although you get a "did you mean...?" prompt correcting the formula. I think the 1st is probably fine, the 2nd probably isn't.

Greedo

Posted 8 years ago

Reputation: 267

1

brainbool, 1 byte

.

Try it online!

brainbool is like brainfuck, except cells can only contain 0 or 1. Outputting in brainbool always produces an ASCII 0 or 1. All cells start out as 0, so . will output 0.

Zack C.

Posted 8 years ago

Reputation: 491

1

Forth, 6 bytes

1e3 f.

Try it online

Output:

1000. 

Note the trailing space.

mbomb007

Posted 8 years ago

Reputation: 21 944

1

T-SQL, 21 15 bytes

print space(15)

Try it online

Output:

               

mbomb007

Posted 8 years ago

Reputation: 21 944

Looks like a space is a valid output, so PRINT SPACE(15) would save you some bytes. – BradC – 6 years ago

Nice! Thanks... – mbomb007 – 6 years ago

1

WinDBG, 7 bytes

??1;$$$

Outputs:

int 0n1

How it works:

??1;        Evaluate (and implicit print) 1 as a C++ expression
    $$$     Comment, ignored

milk

Posted 8 years ago

Reputation: 3 043

1

shortC, 15 10 8 7 6 bytes

AR"%6d

Output: A random integer x with y spaces before it. y = strlen(itoa(x))

Directly stolen from Doorknob.

MD XF

Posted 8 years ago

Reputation: 11 605

1

Java, 70 bytes

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

Prints 69 spaces and a zero.

Arnaud

Posted 8 years ago

Reputation: 8 231

1

Scala, 9 bytes

()=>"x"*9

This is a function which returns "xxxxxxxxx".

Try it online

corvus_192

Posted 8 years ago

Reputation: 1 889

1

R, 8 9 bytes

cat(8^8)

Prints 16777216 to stdout. cat(F) would have been better, but there isn't a trailing newline on the output. Thanks to @user2390246 for a byte.

Try it online!

MickyT

Posted 8 years ago

Reputation: 11 735

1

Brian & Chuck, 9 bytes

?{-?
	.{?

Try it online!

Prints ?????????.

The first character on the second line is a tab.

Explanation

The tab's code point is 9 and it's just used as a counter to loop the correct number of times.

The program starts by immediately switching to Chuck with ?. The . prints that ?, { currently does nothing and ? switches back to Brian.

We now start the main loop which runs 8 times. { moves the tape head on Chuck back to the first cell, i.e. the tab. - decrements this counter. Once the counter hits zero, ? does nothing and the program ends. But until that happens it switches control back to Chuck. Then . prints another ?, { resets the tape head on Brian to the beginning and ? hands control back to him. This way, the two instances alternate between decrementing the counter on Chuck and printing a ? on Brian.

Martin Ender

Posted 8 years ago

Reputation: 184 808

1

Frink, 9, 11, 10 bytes

print[13!]

Outputs:

6227020800

Such a ... boring solution, sigh.
*no trailing newlines.
*Although Frink parses unicode exponents {+- 0-9}, print[9⁹] is 11 bytes, not 9.
Frink has a large data file of constants, but I haven't yet found a < 4 char one that outputs < 11 bytes. (constants have units, and frink is very verbose by default)

maybeso

Posted 8 years ago

Reputation: 51

That seems to be 3 bytes. – Ørjan Johansen – 8 years ago

grr, of course it is. So silly of me to trust the byte size of the native-editors saved file without reloading it to check for corruption. (I did check if it appended a newline) – maybeso – 8 years ago

1

braingasm, 1 byte

Prints 0 (without newline):

:

daniero

Posted 8 years ago

Reputation: 17 193

1

PARI/GP, 2 bytes

4!

Prints 24. (This is using the REPL, which is essentially the only way the language is used.)

Charles

Posted 8 years ago

Reputation: 2 435

1

Batch - 6 Bytes

xcopy^

Not sure if this counts, but the typing this in cmd will give the output:

More? 

(With a trailing space)

rahuldottech

Posted 8 years ago

Reputation: 141

typing this command in a batch file can cause security issue - See here: https://stackoverflow.com/questions/15466298/simple-caret-at-end-of-windows-batch-file-consumes-all-memory

– stevefestl – 8 years ago

1

Bash + coreutils, 5 bytes

id -u

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

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

Try it online!

Dennis

Posted 8 years ago

Reputation: 196 637

1

Pyke, 1 byte

k

Try it online!

Pushes the empty string and then prints it with a newline

Blue

Posted 8 years ago

Reputation: 26 661

1

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

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

"@.

Try it online!

Prints 64 46 and a trailing linefeed.

Explanation

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

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

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

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

Martin Ender

Posted 8 years ago

Reputation: 184 808

1

BotEngine, 5 bytes

TIRES

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

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

SuperJedi224

Posted 8 years ago

Reputation: 11 342

1

Perl 5, 7 bytes

say$"x6

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

Chris

Posted 8 years ago

Reputation: 1 313

It seems that say requires a use declaration to enable it. – Ørjan Johansen – 8 years ago

@ØrjanJohansen Normal execution of a perl one-liner is with the -E flag, which automatically enables all optional features, including say. That is, execute it like perl -E 'say$"x6' – Chris – 8 years ago

Saying that "normal execution of a perl one-liner is with -E flag" isn't quite right. However, here on PPCG, we allow Perl one-lines to be ran with -E flag instead of the usual -e – Dada – 8 years ago

@Dada Well, it's up to taste I suppose. There's rarely any reason not to use -E, so I'm in the habit of doing so. – Chris – 8 years ago

1

MainRamCounter, 6 bytes

"a"e6R

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

Breakdown:

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

Output:

aaaaaa

PowPingDone And Stuff

Posted 8 years ago

Reputation: 11

1

Chip, 78+3 = 81 bytes

Flag: -w

Code (Try it online!):

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

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

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


11+3 = 14 bytes (uses version string)

Flag: -V

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

gibberishes

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


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

Flag: -w

Code (apparently some of this is filler?):

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

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

Phlarx

Posted 8 years ago

Reputation: 1 366

1

JavaScript, 35 bytes

Source:

console.log(([]+[])["constructor"])

Output:

function String() { [native code] }

Raven Cole

Posted 8 years ago

Reputation: 19

1

Add++, 2 bytes

Noncompeting as language postdates challenge.

O

Try it online!

Outputs a 0 with a trailing newline.

caird coinheringaahing

Posted 8 years ago

Reputation: 13 702

1

Triangular, 9 bytes

9.(,%<>d]

Try it online!

Formats into this triangle:

    9 
   . ( 
  , % < 
 > d ] ÿ

Triangular auto-inserts ÿ wherever there is no source code to fill the smallest triangle.

Without control flow, the program looks like 9(%d]. Explanation:

  • 9 - push 9 to the stack
  • ( - open loop
  • % - print top of stack as integer
  • d - decrement top of stack
  • ] - jump back to ( if top of stack is truthy

MD XF

Posted 8 years ago

Reputation: 11 605

1

Cubically, 2 bytes

%5

Try it online! Boring. Outputs 45. Also works with %4 (36), %3 (27), and %2 (18).

Cubically, 7 bytes

+5*66%6

Try it online! Outputs 4100625 by adding 45 to the notepad, then squaring it twice.

Cubically, 9 bytes

+5*5555%6

Try it online! Outputs 184528125 by adding 45 to the notepad, then multiplying it by 45 four times.

MD XF

Posted 8 years ago

Reputation: 11 605

1

C#, 53 bytes

Not short, but good enough:

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

Some Facts I can't resist to post:

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

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

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

Adola

Posted 8 years ago

Reputation: 131

1

C#, 12 bytes

()=>1e11+"";

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

Horváth Dávid

Posted 8 years ago

Reputation: 679

1

cQuents, 5 bytes

#3::$

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

Stephen

Posted 8 years ago

Reputation: 12 293

1

PowerShell, 5 bytes

$true

Output (including trailing linefeed):

True

Try it online!

root

Posted 8 years ago

Reputation: 241

1

Common Lisp, 5 bytes

1e+01

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

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

Renzo

Posted 8 years ago

Reputation: 2 260

1

Python 3, 10 bytes

print(1e6)

Try it online!

Mr. Xcoder

Posted 8 years ago

Reputation: 39 774

1

Common Lisp REPL, 2 bytes

'a

returns a followed by a newline

MONODA43

Posted 8 years ago

Reputation: 131

1

Cubically, 2 bytes

%5

Try it online!

Prints the sum of all values on face 5. Face 5 is initialized to

555
555
555

so this prints

45

(Other valid answers: %2,%3,%4)

Kamil Drakari

Posted 8 years ago

Reputation: 3 461

Note – MD XF – 7 years ago

1@MDXF I really need to start reading existing answers more thoroughly instead of just assuming they haven't been solved in Cubically – Kamil Drakari – 7 years ago

1

Implicit, 1 byte

#

Pushes the length of the stack to the stack. Implicit output. Try it online!

1 byte alternatives

  • ß prints a space.
  • ±, $, +, -, *, /, _, and ^ all push 0 if the TIO input box is empty.

MD XF

Posted 8 years ago

Reputation: 11 605

1

Recursiva, 2 bytes

L(

Try it online!

It outputs 26.

L(
L   - Length of
 (  - upper-case alphabet yield

officialaimm

Posted 8 years ago

Reputation: 2 739

1

SmileBASIC, 3 bytes

?#Y

Output:

128

#Y is a constant used for checking the (Y) button, and has a value of 128.

12Me21

Posted 8 years ago

Reputation: 6 110

I wonder if ? is acceptable since it prints a blank line. (Of course it's impossible to actually verify if the console writes a linefeed.) – snail_ – 7 years ago

1

x86 .COM opcode, 9 Bytes

0100 B409          MOV     AH,09
0102 BAFF00        MOV     DX,00FF
0105 CD21          INT     21
0107 C3            RET
0108 24            DB      '$'

l4m2

Posted 8 years ago

Reputation: 5 985

1

Z80Golf, 5 3 bytes

00000000: 3e76 34                                  >v4

Try it online!

The output is vvv. Yay for ASCII-printable machine code!

Disassembly

start:
  ld a, $76 ; 3e 76
  inc (hl)  ; 34

Uses the same concept as the 5-byte one: edit the running code on the fly, and abuse stack underflow.

The program initially loads 'v' to register a, and increments the value at the memory address (hl), which is $0000 where the code $3e is located. Then the code becomes:

  ccf      ; 3f ; Complement carry flag, effective no-op in this program
  halt     ; 76
  inc (hl) ; 34

So the halt is uncovered right away. The stack underflow magic takes the next job; putchar's ret returns to $763f, $0034, and $0000 in the order, and three vs are printed in the process. Now pc is back at the start of the program. ccf is no-op, halt is executed, and the program terminates.


A variation, 4 bytes

00000000: 3e76 343b                                >v4;

Try it online!

The output is vvvv.

Disassembly

start:
  ld a, $76 ; 3e 76
  inc (hl)  ; 34
  dec sp    ; 3b

The added dec sp makes things slightly more convoluted; the stack is arranged so that putchar is run 4 times instead of 3. Without the instruction, the return addresses are $763f - $3b34 - $0000; with it, the addresses are $3e00 - $3476 - $003b - $0000.

Leaving this solution here, in case someone finds the "stack misalignment" technique useful.


Previous solution, 5 bytes

00000000: 2e0a 3e76 34                             ..>v4

Try it online!

Disassembly

start:
  ld l, $0a  ; 2e 0a
  ld a, $76  ; 3e 76
  inc (hl)   ; 34

The second instruction sets up the character to print, which is 'v'. The rest increases the value at the memory address $000a.

The output is vvvvv. Too bad it's not in uppercase (and it's not six v's), otherwise I'd reference the game VVVVVV.

How it works

For no-input challenges, underflowing the stack into the code is a standard technique in Z80Golf. It is done by letting the PC flow beyond the end of the code, so that putchar at address $8000 is reached, a char is printed, and ret is executed.

  • When the code section is run the first time, the instruction at memory $000a becomes ld bc, $0000 (opcode $01 $00 $00). Pretty much no-op, since all registers are zeroed when the program starts. putchar is reached and v is printed once. Then it returns to $0a2e.
  • putchar is run again, v is printed, and the next return address is $763e.
  • Same thing again, return to $0034.
  • Same thing again, finally return to $0000, the start of the code.
  • The code is run again; the instruction at memory $000a is now ld (bc), a (opcode $02). a is $76, so the value is written to memory $0000. After putchar is reached this time, return to $0000 again, and PC meets the new instruction $76 which is... halt! The program ends.

Bubbler

Posted 8 years ago

Reputation: 16 616

1

Flobnar, 9 8 bytes

*<*@
9*<

Try it online!

Outputs 43046721, which is 98. This uses the -d flag to output in decimal. Thanks to Esolanging Fruit for this solution

Jo King

Posted 8 years ago

Reputation: 38 234

8 bytes – Esolanging Fruit – 7 years ago

1

Pascal (FPC), 22 bytes

begin write('':22)end.

Try it online!

:22 pads the write value to be at least 22 characters in length. Here, the write value is an empty string, so this prints 22 spaces.

AlexRacer

Posted 8 years ago

Reputation: 979

1

MathGolf, 1 byte

!

Try it online!

For MathGolf, there is an implicit pop if nothing is on the stack and nothing is in the input. The operator will pop the default value for the type it's requesting, which is either 0, [] or "". That means that a lot of operators will pop implicit zeros from the empty stack, and transform them either into 0 or 1. There are 15 1-byte programs which satisfy the criteria of this challenge, most of them output 0. The rest output 1.

Output 0

*: 0
+: 0
,: 0
-: 0
.: 0
<: 0
>: 0
f: 0
i: 0
w: 0
x: 0

Output 1

!: 1
#: 1
): 1
=: 1

maxb

Posted 8 years ago

Reputation: 5 754

Doesn't ! output 1 as well by default? I remember using that in the How high can you count challenge. Also, your code contains *, but your TIO is . – Kevin Cruijssen – 6 years ago

You're absolutely correct. I created a script to search for all possible correct answers, ! must have gotten lost somewhere. My first thought was , but that's not printable ascii. I'll update the answer once I've looked for more possible correct answers. – maxb – 6 years ago

1

PowerShell, 4 bytes

1..2

Try it online!

Output includes a trailing newline!

Gabriel Mills

Posted 8 years ago

Reputation: 778

You could to try ,1 or +1. Output includes a trailing newline! – mazzy – 6 years ago

Thanks @mazzy, however I think that this method has already been used in this answer.

– Gabriel Mills – 6 years ago

1

Perl6 12 7 bytes

say |^6

Prints the number from 0-5 and a newline for 7 bytes. Suggested by Jo King.

Original

.say for ^7

Scimon Proctor

Posted 8 years ago

Reputation: 131

Nice. I'll have that :D (With attribution of course). – Scimon Proctor – 6 years ago

1

Alchemist, 9 bytes

_->9Out__

Try it online!

Uses up the initial _ atom to output the number of _ atoms remaining (0) nine times.

Nitrodon

Posted 8 years ago

Reputation: 9 181

1

brainfuck, 24 bytes

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

Try it online!

Prints 24 Us.

Explanation:

-[>+<---]    # Generate a U
++++++[      # Loop 6 time
->....<]     # Printing U 4 times each

Jo King

Posted 8 years ago

Reputation: 38 234

1

Keg, 2 bytes

Q.

Outputs 81, which is the ascii value of Q

Try it Online!

EdgyNerd

Posted 8 years ago

Reputation: 1 106

2

I thought ! would be shorter, but the implicit output has a trailing newline :(

– Jo King – 6 years ago

1It also has 3 trailing spaces for some reason – EdgyNerd – 6 years ago

1

Keg, 2 bytes

2-byte answer:


Note that there is a 0x01 here. Try It Online!

user85052

Posted 8 years ago

Reputation:

1

Pyramid Scheme, 32 bytes

^ ^ ^
-^-^-
^-^-
-^-^
^-^-
- -


Try it online!

Outputs 16 zeroes and newlines. I can find a lot of alternative 32 byters with varying amounts of extra padding, but the closest I can come to something shorter is this 27 byte program that outputs 26 bytes

Jo King

Posted 8 years ago

Reputation: 38 234

1

AsciiDots, 8 bytes

.v.
(*$#

This starts with two dots, then duplicates them both, and then outputs all of their values. Might be golf able down to 6 bytes

Try it online!

EdgyNerd

Posted 8 years ago

Reputation: 1 106

1

Actually, 2 bytes

Not winning of course, but I find it relatively interesting. (outputs 10)

1╤

Try it online!

user85052

Posted 8 years ago

Reputation:

1

Keg, 1 byte (SBCS)


Try it online!

Now before you say "Hang on a second, that's 2 bytes: a 1 and a ,", it isn't. Unicode has these really nice symbols where they have a number and a comma combined. It push'n'prints the number 1, the length of the program.

Just don't go pasting this into programs like IDLE and tkinter... they don't particularly like .

Lyxal

Posted 8 years ago

Reputation: 5 253

I don't see that character in the codepage for the language. What byte value does it have? – Jo King – 5 years ago

@JoKing 248. You don't see it because otherwise I couldn't use IDLE to edit Keg.py (as mentioned in my answer `` isn't very much supported) – Lyxal – 5 years ago

Perhaps move the code page to its own file, since you shouldn't have to edit it much? – Jo King – 5 years ago

@JoKing I've been trying to implement the code page using Mego's golflang-encoding repository to no avail. – Lyxal – 5 years ago

1

Go, 22 bytes

func f(){print(0., f)}

On my machine, this prints

+0.000000e+0000x477c88

But the compiler could conceivably allocate f at an address other than 6 hex digits. If you don't like an implementation detail like that, the next best thing is the 26-byte

func f(){print(0.,1<<34)}

which prints

+0.000000e+00017179869184

Purple P

Posted 8 years ago

Reputation: 919

1

W, 2 bytes

1_

Explanation

1  % Push 1
 _ % Negate this number
% Therefore outputs -1

user85052

Posted 8 years ago

Reputation:

1

naz, 2 bytes

2o

Outputs 00.

Quite similar to my answer for Create output twice the length of the code.

sporeball

Posted 8 years ago

Reputation: 461

0

Ohm, 5 bytes

αvssL

Explanation

αvssL
αv    push 'aeiou'
  ss  convert to string two times (NOP)
    L print without newline

Roman Gräf

Posted 8 years ago

Reputation: 2 915

0

Pip, 4 bytes

L2P1

Try it online!

This prints 1\n1\n, at 4 bytes including the newlines.

steenbergh

Posted 8 years ago

Reputation: 7 772

0

Minimal-2D, 72 bytes

/D+++++++++L
 R/D          /LR/>>D     /LR
   R->++>+++<</UU   R->..</UU

Try it online!

Outputs 72 6s. This is BF in a 2D layout.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

0

yup, 12 bytes

0e:::::{0##}

Try it online!

Pushes 6 1s, and, while there are 1 on the top of the stack, output a 0 followed by a 1.

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

0

Jellyfish, 2 bytes

p0

Try it online!

Prints 0 and a trailing linefeed.

Martin Ender

Posted 8 years ago

Reputation: 184 808

0

Rexx 15 Bytes

say left("",15)

Try it here

theblitz

Posted 8 years ago

Reputation: 1 201

0

Lua, 10 bytes

print(1e6)

Outputs:

1000000.0

Try it online!

Felipe Nardi Batista

Posted 8 years ago

Reputation: 2 345

0

Aceto, 9 1 byte

p

Prints the top value on the stack, an implicit 0.


Old solution (9 bytes):

p
¥×
19

Push a 1, push a 9. Multiply the (remaining) stack (by 9; → [1,1,1,1,1,1,1,1,1]).

Implode and print (prints 111111111).

The code is 9 bytes long in UTF-8 because ¥ and × take 2 bytes each.

L3viathan

Posted 8 years ago

Reputation: 3 151

0

Javascript, 10 bytes

alert(1e9)

Nodejs repl (maybe breaking rule)

1

user68584

Posted 8 years ago

Reputation:

0

J REPL, 2 bytes

+1

This outputs 1, then a newline.

Bijan

Posted 8 years ago

Reputation: 781

2TIO doesn't execute the code in a REPL. You need echo or similar in a full program. – Dennis – 8 years ago

0

Python 3 REPL, 2 bytes

1#

Prints 1 followed by a newline (\n)

boboquack

Posted 8 years ago

Reputation: 2 017

1; similarly works. – Mego – 8 years ago

0

REXX 8 Bytes

say 9**8

Prints 43046721

theblitz

Posted 8 years ago

Reputation: 1 201

This outputs a number but the challenge says it must be a string – caird coinheringaahing – 8 years ago

"You may only output bytes in the printable ASCII range (0x20 to 0x7E, inclusive)" Digits fall in that range – theblitz – 8 years ago

0

Python 2, 13 bytes

Code:

print 10**12

Output:

1000000000000

Character Count: 13

Animesh Das

Posted 8 years ago

Reputation: 11

What language is this? – Martin Ender – 8 years ago

Edited. Python 2. Made it in 88 bytes. First timer in code-golf. – Animesh Das – 8 years ago

Welcome to PPCG then! What are the imports for? – Martin Ender – 8 years ago

Initially I thought I could use the randrange() function from the file "random". "import math" is for validating the 1E19 I placed later on. – Animesh Das – 8 years ago

I can see there are better ways to get through, though. For example, I could do away with "import random", since I'm not using randrange() here. – Animesh Das – 8 years ago

Edit #2: Removed import random. Removed unnecessary whitespaces and variables. Newline counted as character. – Animesh Das – 8 years ago

you still don't need import math. Go with print"8". – caird coinheringaahing – 8 years ago

Edit #3: Don't know if this is valid, though. – Animesh Das – 8 years ago

print"8" is 8-bytes but the output is one byte. @RandomUser – Animesh Das – 8 years ago

@MartinEnder Will the latest edit be valid? – Animesh Das – 8 years ago

Oh yeah sorry. How about print"8"*11? – caird coinheringaahing – 8 years ago

@AnimeshDas it was valid before, it just contained lots of unnecessary code. In the current version you'd need to use 10**11 though, because print also prints a trailing linefeed. Then again it seems you've counted a linefeed in your program as well, so if you remove that you can go down to 10**10. – Martin Ender – 8 years ago

So would print 9**11 work? – b_jonas – 7 years ago

0

shortC on modern Linux

8 bytes

Araise(6

Output (with a newline):

Aborted 

10 bytes

Araise(7);}

Output (with a newline):

Bus error 

11 bytes

Araise(14);}

Output (with a newline):

Alarm clock 

11 btyes

Araise(15);

Output (with a newline):

Terminated 

12 bytes

Araise(16);}

Output (with a newline):

Stack fault 

13 bytes

Araise(29);} 

Output (with a newline):

I/O possible 

24 bytes

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

Output (with a newline):

Profiling timer expired 

MD XF

Posted 8 years ago

Reputation: 11 605

0

Bean, 2 bytes

00000000: 253b                                     %;

Explanation

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

Try it online!

Patrick Roberts

Posted 8 years ago

Reputation: 2 475

0

2Col, 2 bytes [non-competing]

=0

Output:

0

Zero, with a trailing newline

Explanation:

    No input, therefore Cell initializes at 0
=0  Set Cell value to 0 and return Cell value
    Implicit: Print return value followed by a newline

Skidsdev

Posted 8 years ago

Reputation: 9 656

0

JavaScript, 32 bytes

Code: btoa(01234567891011121314151617)

Output: MS4yMzQ1Njc4OTEwMTExMjEzZSsyNA==

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

Jamie Barker

Posted 8 years ago

Reputation: 145

Invalid, without explicit output you need to say that it's in a repl – ASCII-only – 6 years ago

Not sure why you're bothering with a thread/post that's 2 years old, but the console.log is for the purpose of the code snippet preview only. Put those commands directly into the browser console and you'll see the correct result. – Jamie Barker – 6 years ago

Well, yeah if you're using console.log it would be "Javascript (<browser name>)". As for the reason why I'm bothering, just because it's two years old doesn't mean it's allowed to be incorrect :P (plus, this question was active recently so I clicked on it and saw this) – ASCII-only – 6 years ago

Well, it's JavaScript, it's never going to win any Code Golf xD – Jamie Barker – 6 years ago

Well, remember here you compete within the same language (well, kinda). The goal here is more to basically catalogue shortest solutions, I guess? – ASCII-only – 6 years ago

plus, would btoa(1000e3) not work? (alert(btoa(9e9)) for output in browser, write(btoa(9e9)) in v8) (also, even 'a'.repeat(n) would probably be shorter than your current solution) – ASCII-only – 6 years ago

Yes, it would. Judging by the time and date I posted this I would say I was bored at work and spent about 2 seconds thinking of something before posting it and then not thinking on it again because it was lunch time ;) – Jamie Barker – 6 years ago

0

Check, 3 bytes (Non-competing)

>]p

Output:

[0]

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

Esolanging Fruit

Posted 8 years ago

Reputation: 13 542

0

GolfScript, 2 bytes

!#

The output is:

1

Try it online!

Koishore Roy

Posted 8 years ago

Reputation: 1 144

0

j, 3 bytes

i.2

output...

0 1

(3 bytes including space)

Richard Donovan

Posted 8 years ago

Reputation: 87

If you can golf your answer down, please don't post a separate answer, just edit in the new solution. – caird coinheringaahing – 8 years ago

0

j, 2 bytes

!4

    returns 24 (factorial 4)

Richard Donovan

Posted 8 years ago

Reputation: 87

0

Tcl/Tk, 18

pack [text .txt 1]

ouputs

unknown option "1"

sergiol

Posted 8 years ago

Reputation: 3 055

0

Google Sheets, 9 4 Bytes

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

=4^5

Or

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

--

Alternatively, 9 Bytes

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

=Rept(1,9

Taylor Scott

Posted 8 years ago

Reputation: 6 709

0

ArnoldC, 309 bytes

Easy.

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

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

Golfable.

Try it online!

V. Courtois

Posted 8 years ago

Reputation: 868

0

ROOP, 7 bytes

/rn/
ha

Try it online!

print IVXLCDM


The constant rn represents the string containing the Roman numerals.

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

DarkPhantom

Posted 8 years ago

Reputation: 191

0

MY, 1 byte

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

Try it online!

Zacharý

Posted 8 years ago

Reputation: 5 710

0

GNU sed, 1 byte

Outputs a newline.

;

Try it online!

Jordan

Posted 8 years ago

Reputation: 5 001

0

Aceto, 1 byte

p

Try it online!

Outputs 0

FantaC

Posted 8 years ago

Reputation: 1 425

0

Pushy, 1 byte

_

Try it online!

Outputs a newline and nothing else.

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

FlipTack

Posted 8 years ago

Reputation: 13 242

0

JsFuck for Firefox 31+ REPL, 604 bytes

[][([]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]
]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]])[!![]+!
![]+!![]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!
![]+[+[]]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]
])[+!![]+[+[]]]+([][[]]+[])[+!![]]+(![]+[])[!![]+!
![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+
[])[+[]]+([]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]
+[+[]]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]])[
!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+
[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]
]+(![]+[])[!![]+!![]]])[+!![]+[+[]]]+(!![]+[])[+!!
[]]](+(!![]+!![]+!![]+!![]+!![]+!![]+[+[]]+(+[])))
+![]

l4m2

Posted 8 years ago

Reputation: 5 985

0

POSIX bc, 1 Byte

a

output:

0

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

Jared K

Posted 8 years ago

Reputation: 893

0

Red / Rebol 5 bytes

1 > 2

Prints:

false

HappySpoon

Posted 8 years ago

Reputation: 1

1Hello and welcome to PPCG. I am unfamiliar with Red / Rebol though this seems to only work in the REPL. If this is the case, please change the language name to something along the lines of Rebol REPL. To conform to our lax guidelines, you could also make your language name a header. – Jonathan Frech – 7 years ago

0

Attache, 8 bytes

!11|Echo

Try it online!

Other programs

9^8|Echo
!11|Echo
3|Echo//3
$A*10|Echo
Echo[$A*11]
$A*10|Print
Print[$A*11]
Echo//3 <|[]
Print//3 <|3
{_!_[0:1]}!Print

Conor O'Brien

Posted 8 years ago

Reputation: 36 228

0

Husk, 2 bytes

s"

Try it online!

Prints "".

Husk, 2 bytes

_1

Try it online!

Prints -1.

Unrelated String

Posted 8 years ago

Reputation: 5 300

0

Embodiment of Ignorance

Posted 8 years ago

Reputation: 7 014

@JoKing yes I did, thanks – Embodiment of Ignorance – 6 years ago

0

Python 3 only 3 bytes.

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

Ishaq Khan

Posted 8 years ago

Reputation: 351

3This is a snippet for the REPL interpreter, not a full program or function. – Stephen – 6 years ago

0

TI-BASIC, 2 bytes

ᴇ1

Prints 10.

is this one-byte token.

Tau

Posted 8 years ago

Reputation: 1 935

0

Python 3, 10 bytes

print(1e6)

Try it online!

movatica

Posted 8 years ago

Reputation: 635

you can save 1 byte by using Python 2: print 1e6 – Beefster – 6 years ago

Changing the language is not the point ;) – movatica – 6 years ago

This is also an exact duplicate of another answer. – Beefster – 6 years ago

That's possible. Tried to solve it without scrolling through 12 pages of answers first. – movatica – 6 years ago

Good catch! totally forgot about the newline... – movatica – 6 years ago

4You could do exit(1e5) to print to STDERR, saving 1 byte. – maxb – 6 years ago

0

C++ (gcc), 60 58 bytes

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

Try it online!

movatica

Posted 8 years ago

Reputation: 635

1This will output non-printable ascii. – Beefster – 6 years ago

Doh, missed the first rule, thanx! – movatica – 6 years ago

You don't need the int part of the int main, do you? – Jo King – 6 years ago

Gray area... it just issues a compiler warning, but in fact it'd be invalid C++. – movatica – 6 years ago

0

Bash, 12 bytes

yes|head -n6

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

Beefster

Posted 8 years ago

Reputation: 6 651

0

Gol><>, 1 byte

h

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

Try it online!

KrystosTheOverlord

Posted 8 years ago

Reputation: 681

0

Ahead, 4 bytes

Prints 0000.

4kO@

4k    4 times
  O   pop stack and print 
   @  end

The empty stack always pops 0.

Try it online!

snail_

Posted 8 years ago

Reputation: 1 982

0

Javascript (ES6), 5 bytes

!1+''

outputs the string "false".

vrugtehagel

Posted 8 years ago

Reputation: 251

0

R, 6 bytes

seq(1)

Try it online!

I think we've covered all the other types of R answer already, but this one counts the print method's [1] and trailing newline. There might be some counting technicalities here.

CriminallyVulgar

Posted 8 years ago

Reputation: 501

0

TinCan, 122 bytes

# 31135, A, &                          #
# -256, A, -1                          #
# 0, A, 1                              #

Outputs 122 'a's.

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Try it online!

Explanation:

Lines have a minimum length of 40 characters in TinCan, and there is only one instruction, so 40 bytes would be the shortest feasible TinCan program other than an empty file.

TinCan's interpreter is written in PHP and uses the PHP chr function to output the character value of each number on the stack when the program ends. This also works for values outside the range of 0 to 255, using bitwise and with 255 to get the result.

For this program, I multiplied the length of the program (122 bytes), minus one for the positive case, times 256 and added (256 - 97), 97 being the ASCII value of 'a'. This gives 31135.

The loop then generates a sequence of values starting at -31135 and counting upwards by 256 each iteration. Each value in sequence when processed by chr produces another 'a'. When the variable A becomes positive, the program exits and prints 122 'a's.

With the fixed line length, golfing this down would require removing one whole instruction, which I don't believe is possible. But I'd be happy to be proven wrong!

Dehodson

Posted 8 years ago

Reputation: 111

0

SNOBOL4 (CSNOBOL4), 23 bytes

	OUTPUT =DUPL(1,22)
END

Try it online!

Outputs 22 1s and then a newline.

Giuseppe

Posted 8 years ago

Reputation: 21 077

0

Runic Enchantments, 2 bytes

m@

Try it online!

One of several possible programs that satisfies the challenge. This one is just the least obvious. Rather than pushing a value literal (a-f) to the stack, instead push the current value of the IP's energy/mana to the stack (which is initially 10).

1 byte solutions are impossible as Runic requires an output byte and a termination byte (both satisfied by @) as well as a Thing-To-Print byte (m).

Draco18s no longer trusts SE

Posted 8 years ago

Reputation: 3 053

0

Underload, 6 bytes

()aaaS

Outputs ((())), since a just puts brackets around the top item of the stack.

Try it Online!

EdgyNerd

Posted 8 years ago

Reputation: 1 106

0

Ohm v2, 1 byte

Try it online!

or

Try it online!

Ohm, 1 byte

º

Try it online!

or

°

Try it online!

Explanation

In Ohm if a component requires an input but no inputs are provided a 0 is implicitly pushed to the stack, so the output is 20 for the first program (in each version) and 100 for the second.

Cinaski

Posted 8 years ago

Reputation: 1 588

0

33, 1 byte

o

Prints 0, the default value of the accumulator.

i also works, printing a trailing newline.

TheOnlyMrCat

Posted 8 years ago

Reputation: 1 079

0

8086/8088 machine code, 6 bytes

b8 21 21    mov ax, 2121         Load 0x2121 into AX.
ef ef ef    out [dx], ax (x3)    Output AX (2 bytes) to port [DX], 3 times.

Assumptions:

  • The output may be sent to I/O port 0.
  • DX is initialized with 0.

Joke answer:

ee    out [dx], al    Output AL (1 byte) to port [DX].

Assumptions:

  • The output may be sent to I/O port [DX], whatever that is.
  • AL is initialized with an ASCII character.

Tanner Swett

Posted 8 years ago

Reputation: 531

0

brainfuck, 36 bytes

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

Try it online!

Krzysztof Szewczyk

Posted 8 years ago

Reputation: 3 819

0

Python 3, 13 bytes

print('x'*13)

Try it online!

Dat

Posted 8 years ago

Reputation: 879

0

Zsh, 9 bytes

<<<$[9E7]

try it online!

roblogic

Posted 8 years ago

Reputation: 554

1Should technically be 9E6 because of the trailing newline. – GammaFunction – 6 years ago

0

Or, 5 bytes

 fals

This returns false (this should be a five-character constant) onto the stack, which can be used later in the program (or not really, none of the current known instructions in Or access non-top items).

Explanation

From the IRC log:

14:01 < fungot> mroman_: the command to push false is ' f'

Since fungot had not yet presented the full language, all that we know in the current interpreter is that extra instructions do nothing.

 f    Push false onto the stack
  als All of those are recognized as NOPs in the current implementation.

user85052

Posted 8 years ago

Reputation:

Languages must have a known implementation to be valid here. – Ørjan Johansen – 5 years ago

The known implementation is here.

– None – 5 years ago

0

Wren, 2014 bytes

Fn.new{"1"*14}

Try it online!

Explanation

Fn.new{      } // Anonymous function
       "1"*14  // Returning the string "1" repeated 14 times

user85052

Posted 8 years ago

Reputation:

0

Python 3, 29 bytes

s='s=%r;print(ss)';print(s%s)

Try it online!

Output

s='s=%r;print(ss)';print(ss)

A more quine-like answer than this answer

Mukundan

Posted 8 years ago

Reputation: 1 188