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

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

# 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>

• For the bonus, does the output have to be exactly n * program length bytes, or is that a minimum? – xnor Oct 2 '15 at 23:19
• It has to be exact – Daniel M. Oct 2 '15 at 23:20
• Looks like the code snippet has to be modified to handle negative scores. – El'endia Starman Oct 2 '15 at 23:49
• 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. – xnor Oct 2 '15 at 23:58
• 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. – xnor Oct 2 '15 at 23:59

# Pyth, 8 - 25 = -17 bytes

mU2?zvz2


Demonstration

Note: This only works in the online compiler, because it removes the trailng newline.

Output form:

[[0, 1], [0, 1], [0, 1]]


# GolfScript, 1 byte

1


At the end of a GolfScript program, the interpreter outputs everything that's on the stack, and a trailing newline. So the output of the above program is 1 with a trailing newline, two bytes.

main=print[92..102]


Outputs: [92,93,94,95,96,97,98,99,100,101,102] and a NL.

• The output is 37 long... unless you count newline. In that case I suggest main=print[3..15]. Actually, per OP, "No adding unnecessary whitespace to the source code to change its length". – Leif Willerts Oct 4 '15 at 14:15
• @LeifWillerts: the newline is there, so it counts. Removed the whitespace. – nimi Oct 4 '15 at 14:31

# T-SQL, 16 bytes

SELECT SPACE(32)


This returns a string of 32 spaces. Can't think of anything fancier at the minute.

• Save one byte with PRINT SPACE(30) – BradC May 21 '18 at 21:35

# Retina, 25 24 - 25 = -1 bytes

^$11 1 11111111! &!111  Use the -s flag to run the code from a single file. Input is in unary. For reference, without the bonus, there's a 1-byte solution: !  Really any single character would do, so long as it's a valid regex (so an unmatched parenthesis wouldn't). This will just print the number of matches (zero in this case) followed by a newline, which makes two bytes. ## Explanation A translation of the sed answer, requires 25 bytes (computed as 5x5) instead of 40 (see revision history). However, we can do better in Retina: First, we default the input to (unary) 2 if it's empty with: ^$
11


Now we turn each 1 into eight 1s and an exclamation mark with:

1
11111111!


What we ultimately want is to print 24 bytes for each of those chunks. The idea is to get a "free" multiplication by using Match mode's options to a) print all matches and b) consider overlapping matches. We also note that each match is terminated by a linefeed. So if each match is 3 bytes, we'll get 4 bytes per line, and need 6 lines. How many possible 3-byte matches are there in a string of 8 ones?

11111111
111
111
111
111
111
111


Six. How convenient :). So we the final stage is simply:

&!111


Which means that for each unit of source code length requested, we print:

111
111
111
111
111
111


with a trailing newline, which is exactly 24 bytes.

Note that this is why we needed to append the exclamation mark to each line: it ensures that we don't get additional matches which are shared between chunks.

# SWI-Prolog, 3 bytes

nl.


This outputs:

\n
true.


(the \n is printed as an actual linefeed, not the two characters).

• Is the dot after true in the Prolog specs or is it interpreter specific? The swish online interpreter doesn't print it allowing the 2-byte program p. – Emigna Dec 16 '15 at 18:01
• @Emigna Hmm, then I guess it depends on what interpreter you have. I used SWI-Prolog, so I will update the title of this answer to be SWI-PROLOG specific and you may answer with a shorter solution for other interpreters. – Fatalize Dec 17 '15 at 8:37

# Jelly, non-competing

-21 bytes This answer is non-competing, since the challenge predates the creation of Jelly.

o2⁴x


The source code is 4 bytes long and qualifies for the -25 bytes bonus. Output is a list of 16's.

Try it online! without input or with input.

### How it works

o2⁴x  Main link.
If there's input, the left argument is set to that input.
Otherwise, it defaults to 0.
o2    Logical OR of the left argument and 2.
The return value is now either the input or 2.
⁴x  Repeat 16 that many times, creating an array.


16 is two bytes long, and n copies are separated by n - 1 instances of , . That, plus the two bytes of [ and ] gives 2n + 2(n - 1) + 2 = 4n bytes of output.

• It seems that you have (ab)used array representations here. – Erik the Outgolfer Sep 17 '16 at 9:21

## Brian & Chuck, 9 bytes

{?
#.{-?


Try it online! There's a single unprintable \x12 (code point 18) before the first { which gets decremented each iteration, giving an output of 18 ?s.

# PHP, 34 bytes - 25 = 9

$i=34*$argv[1];while($i--)echo"x";  34 bytes generating 34 * $argv[1] characters

### 2x version, 25 bytes

$i=50;while($i--)echo"x";


25 bytes generating 50 characters

# Batch, 17 bytes

@type %0 %0 2>nul


This one does not require a special locale (as the date solution does)

And it does not require %PATH% to be set. (No environment at all, for that matter)

2>nul is required to supress type to output the filenames on stderr (which it does when more than 1 file is printed)

Currently I couldn't conjure up a f(x)=x*N solution that is shorter than 17+25 bytes

This is the best I could come up with:

@if !%1 == ! (call %0 2) else (for /l %%x in (1,1,%1) do @type %0 2>nul)


Which has a score of (72-25) 45 bytes

• You could golf that n solution by 12 bytes to a total of 60 (-25 = 35): @if !%1==! (call %0 2)else for /l %%x in (1,1,%1)do @type %0, done by removing some unecessary spaces and parentheses. Also, the 2>nul thing is only needed for multiple files, and since you're only doing type %0, it isn't required there. Finally, I'm not 100% sure on how bytes for flags are counted, but you could possibly use the /v flag (if it only counts as 1 byte) on cmd to remove those 2 pesky @. Cheers! – Matheus Avellar Sep 13 '17 at 2:51
• I realize it's still not perfect as 35 is still more than 17, but it's something :T – Matheus Avellar Sep 13 '17 at 2:53
• I wonder isn't this 'file io'? – stevefestl Sep 22 '17 at 23:51

# JavaScript, 2 bytes

f=(n=2)=>("f="+f).repeat(n)

• +27 bytes source code
• -25 bytes bonus

# Brain-Flak, 128 bytes

Try it online!(You probably wont be able to finish it before the universe ends)

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


## How it works

It starts simply by pushing ninety-eight to the stack:

((((((()()()){}){}){}){}()){})


It then implements my Triangulation algorithm:

(*push n*{({}[()])}{})


seven times.

This results in

1447283887869053957595051227533274962011504066726596247765427442496031260270109555118382532157345193860142997726793245725173763195275989332247013823819162395404940274645651775376645319691872778284304403703355308050412897911161964450479105938633399903762942


The program then terminates and spits the contents of the stack to the terminal. Since insert atrociously huge number here is 256 characters long in base 10, the output is exactly twice the source code's length.

As one might tell I used a computer aided search to find this solution. This is almost certainly the shortest solution using the triangulation method I outlined.

# PHP, 56-25bytes = 31 bytes

I wanted one where size of the code doesn't matter:

<?=str_repeat(file_get_contents(__FILE__),$n!=''?$n:2)?>


Or a more modern version:

<?=str_repeat(file_get_contents(__FILE__),$argv[1]?:2)?>  • I started down the same path but "No file/disk/network io allowed." – Alex Howansky Aug 4 '16 at 15:27 • Where do you get $n from? Try $argv[1]?:2; it has the same length as your expression. – Titus Jan 27 '17 at 6:47 • This post is a year old, where register_globals was frowned upon, but not forbidden :) – Martijn Jan 27 '17 at 8:04 • register_globals went off in the default config with PHP 4.2 (about 15 years ago). The other one requires 5.3 or later. No file/disk/network io allowed. But who cares; it´s nice. And you can still save four bytes with $n?$n:2. – Titus Jan 27 '17 at 16:14 # PHP no bonus, 19171614 9 bytes <?=99**9;  prints 913517247483640899 longer versions: • echo date(Mc); 14 bytes print the first three letters of the month name followed by an ISO-8601 formatted date (like 2017-01-26T21:57:38-08:00 - length=25) • var_dump([01]); 15 bytes print array(1) {\n [0]=>\n int(1)\n}\n • echo decbin(~0); 16 bytes print 32 ones (on a 32 bit machine) • echo md5(12345); 16 bytes print 827ccb0eea8a706c4c34a16891f84e7b • <?=str_pad(_,34); 17 bytes print one underscore and 33 spaces. • <?=decbin(2**33); 17 bytes print a 1 and 33 zeroes • printf("%34d",0); 17 bytes print 33 spaces and a 0 • echo date(uuuuuu); 18 bytes print 6*6 zeroes • <?=date(uuuuYY); 16 bytes print 6 zeroes four times and the current year twice close but no cigar: • <?=pi(); 8 bytes print 3.1415926535898 (15 characters; 64 bit machine) • <?=log(2); 10 bytes print 0.69314718055995 (16 chars; 64 bit) • <?=date(wc); 12 bytes print 26 chars • var_dump(_.pi()); 17 bytes print 30 chars (64 bit) # [Non-Competing] C, 16 Code: //score=16 bytes  Outputs: error: ld returned 1 exit status (32 bytes) # Excel,10 Bytes =pi()&1234  prints 3.141592653589791234 • A different approach gives 5 bytes: =10^9' – Wernisch Sep 24 '19 at 13:29 # Carrot, 4 bytes, non-competing .^*7  Prints ........ (8 .s). Try it online! ### Explanation .^ Sets the stack-string to "." *7 Append seven duplicates of the stack-string to itself Implicit output  # dc, 4 bytes 1dff  prints 1 1 1 1  TIO • nope. 1 \n 1 \n 1 \n 1 \n @Stephen – cab404 Sep 17 '17 at 4:35 # Pyth, 3 - 25 = -22 bytes This was an accident, but it magically works, however, to make this work, I had to waste a byte. yDQ  This returns a range between 0-input. The brackets, commas, and spaces add up to Q times 3. I honestly can't quite tell you how or why this works. Test Suite # Pyth, 1 byte (no bonus) d  Returns a space and a newline, which is 2 characters. • doesn't appear to work for no input – ASCII-only Apr 20 '18 at 4:22 • @ASCII-only I believed that input was always going to be in regex /[0-9]+/, unless otherwise specified. – Stan Strum Apr 20 '18 at 4:24 • "If no input is provided, n must default to 2." idk though, the question may be unclear :/ – ASCII-only Apr 20 '18 at 4:30 • @ASCII-only Give me 24 hours while I finish up my 2 weeks of work due tomorrow. It's 9;31 UTC-8 – Stan Strum Apr 20 '18 at 4:31 • Note: @Blue just pointed out that input will always be positive so you can just do logical or – ASCII-only Apr 20 '18 at 7:34 # LibreLogo, 21 bytes Code: input_half_the_length  Result: Unknown name: ‘input_half_the_length”.  # Minecraft Functions (18w15a, 1.13 snapshots), 26 bytes Uses one function named ab ab function ab tp @e ~0 ~0 ~0  It just recurses until it hits the default limit of 65536, at which point it outputs Executed 65536 commands from function 'minecraft:ab' # Perl 5, 17 - 25 = -8 Tip of the hat to primo for getting me to reread perlvar die$/x(<>*17||34)


Try it online!

# Brachylog, 10 bytes - 25 = -15

{2|};Ṿj₍jw


Try it online!

         w    Print
Ṿ        "aeiou"
j       concatenated with itself
2            two
{ |}          or whatever else the input is
;  ₍      times
j     concatenated with itself again.


A version without the bonus:

# Brachylog, 3 bytes

ẈẈw


Try it online!

Bypasses the ban on unnecessary whitespace by using unnecessary variable unification instead.

  w    Print
Ẉ     the built-in constant "aeiouy" which is
Ẉ      the built-in constant "aeiouy".


A version without any silly redundancy:

# Brachylog, 4 bytes

1j₈w


Try it online!

   w    Print
1       the digit 1 (could be any digit other than 0)
j      repeated
₈     eight times.


# Runic Enchantments, 10 bytes -25 = Score: -15

"9q2i{S*$;  Try it online! Program reads a string literal (effectively its own source), concats a 9, pushes a literal 2, and attempts to read input. Reading input and there being no input to read causes the next two commands, {S, to be NOP. This leaves the literal 2 on top of the stack. If there was input, the input ends up on top and the literal 2 on the bottom. Non-numerical input has undefined behavior. Then multiplication between the integer on the top of the stack with the next item (the string) duplicates it n times (Python style). String is exactly the length of the program, being almost a quine, with 9q putting a 9 on the end substituting for the missing " from the beginning. $; prints only the resulting string and terminates (discarding any remaining literal 2 if input was taken).

# INTERCAL, 32 bytes

PLEASE,1<-#64DOREADOUT,1DOGIVEUP


Try it online!

Prints 64 null bytes and takes no input. If you like your output printable, the next version is for you:

# INTERCAL, 45 bytes

PLEASE,1<-#90DO,1SUB#1<-#4DOREADOUT,1DOGIVEUP


Try it online!

This is one of those rare cases where C-INTERCAL’s “Turing Tape” I/O is actually helpful. Essentially, what it does is for each value in an array, rather than directly print the corresponding character, is subtract the value from the previous value (starting at 0) mod 256, reverse the bits, and then print that, for every value up to the end of the array. So to print a string of a certain length, you just need to READ OUT an array of that size, and to make it more than just a bunch of null bytes, you only need to set the first element of the array and it’ll print a bunch of something else instead: here, setting the first value to 4 prints 90 question marks, since 0 - 4 mod 256 ≡ 252 = 0b11111100 which is 0b00111111 = 63 backwards, and since every cell in the array after the first has a 0 in it the byte which gets printed never changes on account of that 252 - 0 is still 252.

A version with the bonus which prints null bytes:

# INTERCAL, 67 bytes - 25 = 42 (except it can't default to 2)

DOWRITEIN.1DO.2<-#67DO(1530)NEXTPLEASE,1<-:1DOREADOUT,1PLEASEGIVEUP


Try it online!

A version which prints question marks instead:

# INTERCAL, 80 bytes - 25 = 55 (except it can't default to 2)

DOWRITEIN.1DO.2<-#80DO(1530)NEXTPLEASE,1<-:1DO,1SUB#1<-#4DOREADOUT,1PLEASEGIVEUP


Try it online!

Uses a call to syslib for multiplication of the input with 80 into :1. (Also note that INTERCAL’s native number input format is the digits of a number spelled out with a trailing newline.)

• Also also note that both versions which take input can't handle not taking input and are thus invalid. – Unrelated String Apr 1 '19 at 18:04

# Boolfuck, 21 bytes

+[[>+>+[<;;;]<]>+>>]>


This program outputs 330 bits (41.25 bytes) which get buffered to 42 bytes. I found it by systematically (but not quite exhaustively) searching through several million possible candidates.

Here is a hexdump of the output:

00000000: fc0f ffe3 ffc7 ffff ff1f fe3f ffff f8ff  ...........?....
00000010: ffff ffff c0ff fe3f ffff ff1f ffff ffff  .......?........
00000020: ff1f ffff ffff ffff fe00                 ..........


Try it online!

I also recommend taking a look at this in fatiherikli's Brainfuck visulizer (optimized and with minimal delay of course).

# Guile (5)

"oof" outputs \$1 = "oof"

• Hello, welcome to PPCG! – James Apr 9 '19 at 17:28

# Bash, 10 bytes

yes|head -


outputs 10 lines of ys for 20 total bytes output.

# Triangular, 108 7 bytes

tdC%.y


Try it online!

Prints odd numbers from 11 to 1 descending, twice each.

Triangular executes as if written in the shape of a triangle. For example, if your program was 123456, the triangle representing your program would be drawn like this:

  1
2 3
4 5 6


The program executes starting from 1, and has a Southeast direction (I.e., the above would run as 1, 3, 6). This explanation is for its actual execution order, which is why it doesn't visually look the same as the submission.

Ungolfed/Directional

   t
d C
% . 
y

-------------------------------------------------------------------

t             - If ToS != 0, set direction to SouthEast
C            - Push 12
- Set direction to NorthWest (This means we hit "t" with ToS > 0)
d          - Decrement the top value of the stack
%y        - Print the top value of the stack, then change direction to NorthEast if ToS != 0


Previous Version (8 bytes):

Dn,%d./<


## ><>, 29 + 2 (-v flag) - 25 = 6

l0=?21-:0(?;fe+1-ao:0=f*e+0.~


Takes input on the stack, which I believe is populated through -v on the official interpreter. Prints newlines only.