101
\$\begingroup\$

The Challenge

Write a complete program that writes twice as many bytes to standard output as the length of the program.

Rules

  • The program must write ASCII characters to the standard output.

  • The contents of the output doesn't matter.

  • The output, measured in bytes, must be exactly twice the length of the program, also measured in bytes, unless you fulfill the bonus.

  • Any trailing newline is included in the output's byte count.

Bonus

Your program can optionally take a number, n, as input. If so, the output must be exactly n * program length bytes. You can assume that n will always be a positive integer. If no input is provided, n must default to 2.

If you do this, you can subtract 25 bytes from your score.

Shortest program wins.

Restrictions

  • No standard loopholes.

  • The program must be at least 1 byte long.

  • No adding unnecessary whitespace to the source code to change its length. Similarly, comments don't count.

  • Unless you fulfill the bonus, the program must accept no input. If you do fulfill the bonus, the integer must be the only input.

Lowest score (program length in bytes - bonus) wins.

The shortest answer for each language wins for that language.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=59436,OVERRIDE_USER=41505;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){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
23
  • 1
    \$\begingroup\$ For the bonus, does the output have to be exactly n * program length bytes, or is that a minimum? \$\endgroup\$
    – xnor
    Oct 2, 2015 at 23:19
  • 2
    \$\begingroup\$ It has to be exact \$\endgroup\$
    – Daniel M.
    Oct 2, 2015 at 23:20
  • 3
    \$\begingroup\$ Looks like the code snippet has to be modified to handle negative scores. \$\endgroup\$ Oct 2, 2015 at 23:49
  • 44
    \$\begingroup\$ A bonus of -25 is basically mandatory for some languages, since it lets them achieve a negative score. In the future, I'd suggest using a percent bonus, or just making the bonus the question if you really want answers to go for it. Or, just don't have a bonus. \$\endgroup\$
    – xnor
    Oct 2, 2015 at 23:58
  • 4
    \$\begingroup\$ For "no input is provided", do we assume the empty string is passed in? I can't see how one would deal with the user never typing in an input and the program just waiting. \$\endgroup\$
    – xnor
    Oct 2, 2015 at 23:59

285 Answers 285

1
4 5
6
7 8
10
1
\$\begingroup\$

PHP, 45 bytes

<?php print number_format(pow(10,66))."a"; ?>

output:

1,000,000,000,000,000,132,394,543,446,603,018,655,781,305,157,705,474,440,625,207,115,776a

<?php              //PHP start tag
print              //Prints what's ahead
number_format(arg) //format what's inside the parentheses as a number, with separators. (Used as escape function for having scientific notation result 
pow(base,exp)      //Gets the value of the `base` raised to the power of `exp`
.                  //Concatenation operator
"a"                //String of "a"
?>                 //End tag for PHP
\$\endgroup\$
1
\$\begingroup\$

Forth (gforth), 36 - 25 = 11 bytes

: x depth 0= if 2 then 36 * spaces ;

How it works:

Checks if no value is on the stack (depth 0=). If that is the case, push 2. Then just print n * 36 spaces.

Forth (gforth), 2 bytes

.S

Only works if the stack is empty. Prints <0> (<, 0, > and space)

\$\endgroup\$
1
\$\begingroup\$

Braingolf, 1 byte

Prints 0 and a newline.

l

Try it online!

Explanation

l

l      push length of the stack to the stack
       implicit output
       implicit newline printed at end of program
\$\endgroup\$
1
\$\begingroup\$

><>, 15 + 2 (-v flag) - 25 = -8 bytes

2{f*:?!;0n1-30.

Explanation:

2{ puts 2 at the bottom of the stack. If no input was provided, this means it is at the top. Otherwise, the provided input will be at the top.

f* multiplies the input by 15 (the length of the program)

We then go into a loop: :?!;0n1-30.

:?!; ends the program if the counter is 0.

Otherwise, 0n prints 0, 1- decrements the counter, and then 30. goes back to the start of the loop.

\$\endgroup\$
1
\$\begingroup\$

05AB1E, -23 bytes (non-competing)

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ This doesn't default to 2 for no input \$\endgroup\$
    – Jo King
    Aug 23, 2018 at 2:59
  • \$\begingroup\$ @JoKing it used to, 05AB1E basically got a massive overhaul. It for sure used to default to 10. \$\endgroup\$ Aug 23, 2018 at 4:32
  • \$\begingroup\$ Doesn't work for 1. I don't see how this works, so may you explain your program? \$\endgroup\$
    – user85052
    Dec 22, 2019 at 14:15
1
\$\begingroup\$

Java 8, 16 15 bytes

Golfed a byte by using a for loop instead of a while loop. (back to where I was before :P)

u->{for(int x=0;++x<40*u;)out.print(1);}

Using a static import to reduce the code by 7 bytes, this prints out 1 40u times, where u is the integer taken from input. Since the program code is 40 bytes long and I incorporated the bonus, that leads me with 40 - 25 = 15 bytes.

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ On TIO, this outputs in scientific notation, which means that the output for u.c(1) is ~6 bytes. Is that also how it works for you locally? If so, I'm not sure this is working as intended. \$\endgroup\$
    – Stephen
    Aug 14, 2017 at 15:52
  • \$\begingroup\$ I, for some reason, thought the output simply had to represent double the length of the source code. Thanks for pointing it out; fixed accordingly. \$\endgroup\$
    – NotBaal
    Aug 15, 2017 at 15:22
1
\$\begingroup\$

Ly, 17 - 25 = -8 bytes

"9>n[<&s&ol>1-]<;

Try it online!

A simple quine variant. Outputs 9>n[<&s&ol>1-]<; input times. (there's a tab at the end)

3 bytes, no bonus

"&|

Outputs:

38 124

Try it online!

\$\endgroup\$
1
\$\begingroup\$

TI-BASIC, -20 bytes

10^(5Ans-1

As Julian Lachniet mentioned in a comment on his answer, TI-BASIC does not accept empty input, so I guess this is TECHNICALLY 5 bytes.

Note that 10^( is only one byte, as is Ans.

All this does is print a power of ten with 5Ans digits.

\$\endgroup\$
1
\$\begingroup\$

Pyke, 1 byte

T

Try it here!

Outputs 10

\$\endgroup\$
1
\$\begingroup\$

Pyke, 5 bytes -25 = -20

2|}hV

Try it here!

\$\endgroup\$
1
\$\begingroup\$

Pyke, 3 bytes -25 = -22

2|S

Try it here!

2|  -  input or 2
2|S - range(1, ^)
\$\endgroup\$
3
  • \$\begingroup\$ Not sure if this is valid, input of 0 acts as if n=2, but I guess there isn't really a way to avoid that \$\endgroup\$
    – ASCII-only
    Apr 20, 2018 at 4:28
  • \$\begingroup\$ It says input will be a positive integer though it doesn't specify if 0 is valid or not \$\endgroup\$
    – Blue
    Apr 20, 2018 at 7:33
  • \$\begingroup\$ Oh, fair enough \$\endgroup\$
    – ASCII-only
    Apr 20, 2018 at 7:33
1
\$\begingroup\$

Windows Batch, 148 144 73 30 bytes

@echo %OS%%OS%%OS%%OS%%OS%%OS%

The %OS% system variable should be Windows_NT on most Windows NT systems.

6 of this %OS%(i.e. Windows_NT) is exactly 60 character, which is codeLength * 2.

\$\endgroup\$
1
\$\begingroup\$

Japt, 1byte

My previous solution-with-bonus was invalid as I missed the requirement that input should default to 2. This is a stop-gap until I have a few minutes to come up with something better.

A

Output: 10

Try it online

B-G would also work, outputting 11-16 respectively, as would H (32), I (64) & J (-1).

Slightly less trivial solutions include (1000) and 8³² (262144), among many others.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ If no input is provided, n must default to 2. \$\endgroup\$ Aug 16, 2017 at 21:09
  • \$\begingroup\$ As Taylor Scott said, the input must default to 2. \$\endgroup\$ Sep 29, 2017 at 19:41
  • \$\begingroup\$ @EriktheOutgolfer: Ah, missed that (the requirement and Taylor's comment). Will update with a bonusless solution momentarily as a stop-gap 'til I get a few minutes to come up with something else. \$\endgroup\$
    – Shaggy
    Sep 29, 2017 at 19:53
1
\$\begingroup\$

Scala, 35 bytes

object X extends App{print("X"*70)}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

BASH + coreutils, 22 (-25) = -3 bytes

printf %$[${1:-2}*22]d

Pass repeat count as 1st argument. Omit argument to default to 2 repeats.

\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 24 18-25= -7 bytes

N=2INPUT N?@A*N*9;

In SmileBASIC, labels (@LABEL) are treated as string literals in expressions, so you can make a 2 or more character long string without any quotes. Then it just has to print @A N*9 times to get the correct length.

Without bonus, 6 4 bytes

?1E7

There is a line break after the output, but technically no character is printed to the screen (it is different than if you just printed CHR$(10))

\$\endgroup\$
4
  • \$\begingroup\$ Where is the default value? \$\endgroup\$
    – Titus
    Jan 27, 2017 at 4:41
  • \$\begingroup\$ Alright, Fixed :( \$\endgroup\$
    – 12Me21
    Jan 27, 2017 at 13:30
  • \$\begingroup\$ Could you remove the ; at the end of the first program? I'd argue the linebreak on the console doesn't matter since it doesn't seem to actually write a character to output. \$\endgroup\$
    – snail_
    Apr 20, 2018 at 3:51
  • \$\begingroup\$ The program would then be an odd number of characters long, so you couldn't get an output n* the length by multiplying a string with length 2. \$\endgroup\$
    – 12Me21
    Apr 20, 2018 at 11:20
1
\$\begingroup\$

05AB1E, 7 - 25 = -18 bytes

Saved a byte thanks to Okx.

YI7*ð×?

Try it online!

Explanation

Y       # push 2
 I      # push input
  7*    # multiply top of stack with 6 (program length)
    ð×  # repeat <space> that many times
      ? # print top of stack
\$\endgroup\$
5
  • \$\begingroup\$ Save 1 byte by using YI7*Xs×. There is no need to reverse the stack. \$\endgroup\$
    – Okx
    Jan 26, 2017 at 9:11
  • \$\begingroup\$ @Okx: Good catch. Thanks! \$\endgroup\$
    – Emigna
    Jan 26, 2017 at 9:32
  • \$\begingroup\$ Your current code will print the correct amount of spaces and then a newline :/ \$\endgroup\$
    – Okx
    Jan 26, 2017 at 12:29
  • \$\begingroup\$ @Okx: True. I'm too used to trailing newlines being acceptable. Fixed now :) \$\endgroup\$
    – Emigna
    Jan 26, 2017 at 12:40
  • \$\begingroup\$ @Okx: The Y is there to handle empty input (which should default to 2). \$\endgroup\$
    – Emigna
    Feb 22, 2017 at 19:04
1
\$\begingroup\$

Java, 90 bytes

class T{public static void main(String[]a){for(int i:new int[90])System.out.print("##");}}
\$\endgroup\$
1
\$\begingroup\$

Fission, 7 6 bytes

'#ORR"

This is a variation on a standard Fission quine. With two R's it creates two atoms and reads through the program twice.

Outputs ''##OORRRR##

Try it online!

-1 byte thanks to Jo King

\$\endgroup\$
6
  • \$\begingroup\$ Why do you need the _? '#ORR" seems to work fine \$\endgroup\$
    – Jo King
    Apr 13, 2018 at 8:34
  • \$\begingroup\$ @Joking It outputs ## at the end instead of "". \$\endgroup\$
    – KSmarts
    Apr 16, 2018 at 15:31
  • \$\begingroup\$ And? That’s still twice the bytes. It doesn’t need to be quine-like \$\endgroup\$
    – Jo King
    Apr 16, 2018 at 21:41
  • \$\begingroup\$ @JoKing Ah, I didn't re-read the challenge well. Updated. \$\endgroup\$
    – KSmarts
    Apr 17, 2018 at 13:27
  • 2
    \$\begingroup\$ Or just ORR". \$\endgroup\$
    – jimmy23013
    Apr 17, 2018 at 15:03
1
\$\begingroup\$

Befunge-98, 12 - 25 = -13 bytes

j& 6*1-k.@>2

Try it online!

Prints the correct amount of 0s, each with a trailing space.

How It Works:

j  No effect
 & Gets input. If no input, reflect
         >2 If it reflected put two 2s on the stack 
j  Use one of the 2s to jump past the &
  6*1- Multiply by 6 (length/2) and subtract 1 because it prints an extra 0 later
      k.@ Print that many 0s and end the program
\$\endgroup\$
1
\$\begingroup\$

Attache, 11 bytes

10^20|Print

Try it online!

Attache (bonus), 36 - 25 = 11 bytes

(Safely[ReadInt][]or 2)*36*$x|Output

Try it online!


Uh. Both come out to be the same byte count. So there's that.

\$\endgroup\$
1
\$\begingroup\$

Rebol, 24 bytes

copy/part mold system 48

Prints the first 48 characters of the system object.

Also works with the Red language

\$\endgroup\$
1
\$\begingroup\$

Wolfram Language (Mathematica), 17 bytes - 25 = -8

Echo[10^(17#-5)]&

Try it online!

Assuming giving a function is OK. Prints >> 1, then (17 * input - 5) 0s, then a trailing new line, thus making the output 17 * input bytes long.

\$\endgroup\$
1
\$\begingroup\$

Hummus, 20 bytes (non-competitive)

().(rep('xx',20)).()

Explanation:

().(rep('xx',20)).()   //Empty anonymous function

().                   //Empty parameter declaration 
   (rep('xx',20))     //Repeat 'xx' 20 times
                 .()  //Empty value declaration

In contrast, a non-empty, anonymous function would look like this:

(x).(x*x).(2)

(x).          //Defines x as parameter
    (x*x)     //Defines the output to be x*x or x²
         .(2) //Defines the input of the anonymous function to be 2 (hence the output is 4)

Alternative, 2 bytes:

!0

This works as well and outputs true but since this was posted multiple times already, I found it to be quite a boring solution.

\$\endgroup\$
5
  • \$\begingroup\$ You should add the fact that this is non-competitive. Also is the language a stable release or a WIP ? \$\endgroup\$ Jun 4, 2018 at 19:33
  • \$\begingroup\$ @MuhammadSalman It's in Beta rn (still missing a lot of standard functions) but it's actually quite stable. \$\endgroup\$
    – Azeros
    Jun 4, 2018 at 19:36
  • \$\begingroup\$ Okay. So still a WIP then. I like the language so far (also an interesting choice of languages in which you are building this) \$\endgroup\$ Jun 4, 2018 at 19:48
  • \$\begingroup\$ @MuhammadSalman Thanks! Appreciated! But why did you add the "non-competitive"? \$\endgroup\$
    – Azeros
    Jun 4, 2018 at 19:54
  • \$\begingroup\$ The challenge precedes the language. \$\endgroup\$ Jun 4, 2018 at 20:01
1
\$\begingroup\$

///, 15 bytes

/o/ttttt/oooooo

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Z80Golf, 14 bytes - 25 bytes of bonus = 11 anti-matter bytes (-11 classic bytes)

00000000: 3e02 cd03 8006 0eff 10fd 3d20 f876       >.........= .v

Try it online!

Takes input as a byte value.

    ld a, 2
    call $8003
outer:
    ld b, 14
inner:
    rst $38
    djnz inner
    dec a
    jr nz, outer
    halt
\$\endgroup\$
1
\$\begingroup\$

Python 3, 26 25 Bytes

lambda n=2:print(n*26*'-')

Improved thanks to @JoKing

\$\endgroup\$
0
1
\$\begingroup\$

Come Here, 39 bytes

CALL"9999999999999"iTELLi i i i i iNEXT
\$\endgroup\$
1
\$\begingroup\$

8088 machine code, IBM PC DOS, 35 bytes

Unassembled listing:

        _LOOP:     
AC          LODSB               ; load byte [SI] into AL, increment SI 
8A F0       MOV  DH, AL         ; save original byte in DH 
B9 0204     MOV  CX, 0204H      ; set up nibble counter and shift count 
D2 C0       ROL  AL, CL         ; reverse nibbles (display high order first) 
        _NIB:      
24 0F       AND  AL, 0FH        ; mask low nibble 
3C 0A       CMP  AL, 0AH        ; is < 10? 
72 02       JC   _ASC           ; if so, is a numeric digit 
04 07       ADD  AL, 07H        ; otherwise adjust for A-F hex ASCII 
        _ASC: 
04 30       ADD  AL, '0'        ; ASCII convert 
B4 0E       MOV  AH, 0EH        ; BIOS output char function 
CD 10       INT  10H            ; display char 
8A C6       MOV  AL, DH         ; restore original nibble to AL 
FE CD       DEC  CH             ; decrement nibble counter 
75 EC       JNZ  _NIB           ; if > 0, repeat 
81 FE 0123  CMP  SI, OFFSET _EF ; is SI < last byte? 
7C DE       JL   _LOOP          ; if so, keep looping 
C3          RET                 ; return to DOS 
        _EF EQU $               ; get program size 

This is a complete IBM PC DOS executable that displays itself as ASCII hex, so will always output as twice the program size.

Output

enter image description here

Download and test SELF.COM!

\$\endgroup\$
1
\$\begingroup\$

Excel Formula, 23 - 25 = -2 bytes

=REPT("A",MAX(A1,2)*23)

However, this doesn't work for A1 (n) = 1(!)

Version supporting N=1, 28 - 25 = 3 bytes

=REPT("A",(A1=0)*56+(A1*28))
\$\endgroup\$
1
4 5
6
7 8
10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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