The Challenge

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


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


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.


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

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>

  • 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 '15 at 23:19
  • 2
    \$\begingroup\$ It has to be exact \$\endgroup\$ – Daniel M. Oct 2 '15 at 23:20
  • 3
    \$\begingroup\$ Looks like the code snippet has to be modified to handle negative scores. \$\endgroup\$ – El'endia Starman Oct 2 '15 at 23:49
  • 40
    \$\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 '15 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 '15 at 23:59

265 Answers 265

1 5 6 7 8 9

Brainfuck, 25 bytes

Prints 50 characters, most of which are control characters.


Powershell, -10


Powershell, 2

This answer without the bonus is probably golfier though



  • \$\begingroup\$ @TimmyD does the automatic Newline added after printing count as a character? If so that doesn't work (since you end up at 2n+1). Can use param($b=2)'1'*(24*$b-2) for -1 \$\endgroup\$ – Jonathan Leech-Pepin Oct 7 '15 at 15:11
  • \$\begingroup\$ @JonathanLeech-Pepin No - that won't work, either, for the same reason. See my corrected answer \$\endgroup\$ – AdmBorkBork Oct 7 '15 at 15:14
  • \$\begingroup\$ @TimmyD Actually with -2 at the end of the multiplier it does. According to ISE @{1=23;2=47;3=71}. 24 characters in the function so that works when adding the newline. \$\endgroup\$ – Jonathan Leech-Pepin Oct 7 '15 at 15:26
  • \$\begingroup\$ @JonathanLeech-Pepin Let's continue this discussion in chat \$\endgroup\$ – AdmBorkBork Oct 7 '15 at 16:21
  • \$\begingroup\$ Also, if given no input, it should default to 2. \$\endgroup\$ – LegionMammal978 Dec 29 '15 at 14:08

Sed, 40 - bonus = 15


There's no final newline. Input is in unary, as you'd expect for sed.

We begin by defaulting the input to two. Then we multiply it by 5 and then by 8 for a total multiplication of 40. Our output includes a newline, so we must subtract one before it's printed.

Test results

$ for i in '' 1 11 111 1111; do sed -e 's/^$/11/;s/.*/&&&&&/;s//&&&&&&&&/;s/.//' <<<"$i" | wc -c; done
  • \$\begingroup\$ It took a bit of trial and error to settle on 8*5 for 40; I had 5*3*3 and 7*3*2 as a couple of early attempts. \$\endgroup\$ – Toby Speight Oct 6 '15 at 10:51

Python 3, 30 - 25 = 5

print(int(input()or 2)*30*"X")

It expects input on standard input, an empty input is treated the same as 2.

If we can use the REPL, rather than running as a script, you can remove the print call, to save 7 bytes and bring our score down to -2:

>>> int(input()or 2)*21*"X"

(Note that we multiply by 21, rather than 23 because of the quotation marks that appear in the string's repr.)

A Python 2 version of the same code can be written for three extra bytes (we need to add raw_ to the input, but can replace the pair of parentheses around print's arguments with a single space):

print int(raw_input()or 2)*33*"X"

C#, 77 bytes

102 bytes - 25 bonus

class c{static void Main(string[]a)=>System.Console.Write(new string('x',102*int.Parse(a[0]??"2")));}

Creates a string of the specified length, defaulting to 2.

  • \$\begingroup\$ @ThomasKwa: fixed it by providing a different solution. \$\endgroup\$ – Thomas Weller Oct 7 '15 at 20:50

APL, -8 bytes



  • {0::2⋄⎕}⍬: Try to read a number from the keyboard. If the user entered a valid number, return it; if not, return 2.
  • 17×: multiply it by 17 (the length of the code)
  • '*'⍴⍨: output that many asterisks.

Go, 59 Bytes

package main
func main(){fmt.Printf("%118d",0)}

Prints 0 formatted with padding

Here is a version with argument (145-25 Bytes):

package main
func main(){i:=2
if len(os.Args)>1{fmt.Sscanf(os.Args[1],"%d",&i)}
  • \$\begingroup\$ As has been mentioned in a suggested edit: You should output double length than the one of the code, not the exact length of the code. \$\endgroup\$ – daniero Oct 10 '15 at 13:04

Hassium, 55 Bytes

use Math;func main(){ for(x=0;x<7;x++)print(Math.pi); }



Run and see online here

  • \$\begingroup\$ I thought extra whitespaces are not allowed? \$\endgroup\$ – Leaky Nun Mar 30 '16 at 9:59

Simplex v.0.5, 22 - 25 = -3 bytes

i?[{u(' R)22vM}ug#]2O3
i                      ~~ take input as number
 ?[               ]    ~~ do inside if byte is nonzero
   {          }        ~~ loop inside until zero byte met
    u       v          ~~ up/down strip traversal
     (   )22           ~~ repeats the inner 22 times
      '@R              ~~ pushes an @ and goes right
               ug      ~~ goes to the string strip and clears the strip
                 #     ~~ cease!
                   2   ~~ sets the current byte to two (default N)
                    O3 ~~ goes to the third byte in the source code

Essentially, for each pass of an integer N (input), the string @@@@@@@@@@@@@@@@@@@@@@ is printed once, i.e., N*"@@@@@@@@@@@@@@@@@@@@@@". Since the (...) is a preproccesed command, variable inputs cannot be handled. If they could, then I might shorten the code to something like ('@R)ig whilst handling the special cases. Wouldn't that be something?


Mouse-2002, 32 - 25 = 7 bytes

A quine is not possible in Mouse, unfortunately, else I would have gone that way.

?&DUP 0=[1]32*y:(y.x.>^1!x.1+x:)


? &DUP        ~ get some input; dup it
0 =           ~ if 0
[             ~ then
  2           ~ push 2 instead
]             ~ fi
32 * y:       ~ push 32* and assign into y
(             ~ while(true)
  y. x. > ^   ~ cmp
  1 !         ~ print a 1
  x. 1 + x:   ~ increment x
)             ~ endwhile
$             ~ (implicit) end prog

Note: This answer did not work when the question was asked, so it is not a competitive solution.

Pyth, 6 - 25 = -19 bytes



First, we attempt to take STDIN input and evaluate it. It this throws an error, we use 2 instead. Then, we make a list of that many newline characters. Newline characters take 4 characters to represent ('\n') and there are 2 bytes of list overhead ([] or ,) per element, so it comes out to exactly 6 times longer than the above number.


Perl, 11 bytes


Using the lovely x operator, prints 22 Js. I may be able to find a shorter answer.


Python 2, 11 -1 -6 -11 bytes


Prints 14 * input Ms. Requires a REPL environment.

There may be a way to make it shorter, but at this point I doubt it.


  • Saved 5 bytes by not using int().
  • Saves 5 more bytes thanks to @cat and using a REPL environment.
  • \$\begingroup\$ the question doesn't say assuming a REPL environment is disallowed, so 'M'*input()*14 is shorter for 14 == -11 \$\endgroup\$ – cat Dec 17 '15 at 16:29
  • 1
    \$\begingroup\$ @cat Thanks, I'll add that in now. \$\endgroup\$ – ASCIIThenANSI Dec 17 '15 at 16:42
  • 2
    \$\begingroup\$ If no input is provided, you must default to 2. This does not. \$\endgroup\$ – isaacg Mar 30 '16 at 1:54

MATLAB, 5 bytes


Which displays

a =

By my count that is 10 bytes of output if you include the new-line as 1 byte.


Binary-Encoded Golfical, 13+1 (-x flag)=14 bytes

Noncompeting, language postdates the question.


00 90 01 00 09 17 17 17 17 17 17 17 1D

This encoding can be converted back into the original graphical representation using the included Encoder utility, or run directly by adding the x flag.

Original image:

enter image description here

Magnified 64x, with color labels:

enter image description here

Explanation: Stores 9, prints it seven times (with a newline each time), then turns around and prints it seven more times.


Mumps, 31 - 25 = 6 bytes

My submission was supposed to be unique (but I hadn't checked all of the answers yet) in that the basic "Assume 2x" code and the bonus-enabled code would work out to be the same length!

Basic code:

F J=1:1:28 W 1

Which is 14 bytes.

Here's the initial bonus-enabled code that takes input, anything that equates to '0' including any non-numeric input assumes 2, then outputs the correct number of output characters. This version is 39 bytes not including the bonus.

R I S:+I=0 I=2 F I=1:1:I F J=1:1:39 W 1

Calculating the bonus 39-25=14 bytes as well!

Too bad (for my narrative) that I looked it over and came up with a shorter version of the bonus code:

R I S:+I=0 I=2 F I=1:1:I*31 W 1

This is only 31 bytes long, so 31-25=6 bytes total, and the header reflects this.


Mathematica, 9 bytes


If I am correct, this should output:

>> 20922789888000

with a trailing newline.


Gogh, 3 bytes


You can run it like this:

./gogh o '6GJ'

Or without implicit output (4 bytes):


You can run this using:

./gogh "" "8GJ¡"

The inverted exclamation point outputs the TOS.


6    “ Push the integer literal 6 ”
G    “ Push a range (0, TOS]      ”
J    “ Join the TOS               ”

Python 2, 11 bytes


This outputs 21 zeroes and a newline.


From the Python 2 documentation:

A '\n' character is written at the end, unless the print statement ends with a comma.


Cubix, 15 bytes

Non competing due to language age.

While having some fun with @ETHproductions language, I thought this would be interesting. It turned out a little longer than I thought it would and I'm sure it can be improved.


This maps to a cube with edge length 2

    ( .
    O .
N U . \ ! @ O $
. . u . . . . .
    . .
    . .



N push 10 to the stack
U turn left moved forward turn left
O output number of TOS
$ skip a no op
( decrement TOS, followed by a number of no ops
u turn right, move forward and turn right, more no ops
O output number of TOS, more no ops
\ reflect to the east
! jump end program @ if truthy
O output number of TOS
$ skip N at start of program


Lua, 20 bytes (bonus: 11 bytes)





(Change 40 to 39 if newline is counted)


print(("a"):rep(36*(io.read()or 2)))

(If newline is counted, use print(("a"):rep(38*(io.read()or 2)-1)) [13 bytes] instead.)

  • \$\begingroup\$ Welcome to PPCG! Usually, our community does not like storing input in variables beforehand. It would be better accepted to read from STDIN. \$\endgroup\$ – GamrCorps Mar 30 '16 at 3:47

Underload, 12 bytes




Try It Online


(\/)            # push \/ to the stack        : \/
    a           # add brackets to TOS         : (\/)
     :*         # duplicate the TOS and join. : (\/)(\/)
       ::       # duplicate a couple of times : (\/)(\/)<>(\/)(\/)<>(\/)(\/)
         **     # join stack items            : (\/)(\/)(\/)(\/)(\/)(\/)
           S    # output TOS

Tellurium, 10 bytes


Outputs a 16 times. Simple enough.

More detailed explanation:

µ         Begins reading a string
~         Stops reading a string and stores it in the selected cell
Å         Command set 2
m         Print the cell's value n times

There might be a shorter version using Åw but I'm too tired to do that :P


Java, 85

class A{public static void main(String[]s){for(A a:new A[170])System.out.println();}}

Perl5, 11 bytes

x is string repetition operator

print 1x22
  • \$\begingroup\$ That's only 10 bytes, and you can use 'say' to cut down on two more (run with -M5.010 flag which is free) \$\endgroup\$ – Gabriel Benamy Oct 23 '16 at 18:44

BASH, 19 bytes

54 bytes -25 bonus. Using the variable input for x repeats:

a=$1;for i in `seq 1 ${a:=2}`;do cat $0;done

similar but more readable:

for i in `seq 1 ${a:=2}`; do
 cat $0

19 bytes for a simple sh script.

cat $0 $0
  • \$\begingroup\$ Personally I dislike `backticks` a lot, but it saves 1 char. \$\endgroup\$ – CousinCocaine Aug 4 '16 at 16:11
  • 1
    \$\begingroup\$ DARN, "No file/disk/network io allowed", therefor I exclude this answer from the competition. \$\endgroup\$ – CousinCocaine Aug 4 '16 at 16:14

Turtlèd, 8 bytes (non-competing)



[implicit] initial cell is *, initial char var is *
15       put 15 in register
  :      move right by as many cells as the amount in register
   [*  ] while cell not *
     ,l  write char var, move left 1 cell

Nim, 27 bytes

echo getStackTrace()[0..51]

Prints the first 53 bytes of the following, plus a trailing newline:

Traceback (most recent call last)
<filename>.nim(1)       <filename>

Note that despite having the filename in the output, this answer's validity is not dependant on the length of the filename. For example, saved in x.nim, this is output:

Traceback (most recent call last)

There are nine trailing spaces there. Conversely, when saved in areallylongfilename.nim, this is output:

Traceback (most recent call last)

Newlines are also output in each example. Example usage:

$ nim c length.nim
$ ./length | wc -c

Scala, 52 - 25 = 27 bytes

object A extends App{println("#"*(args(0).toInt*52)}

Simply prints the string # repeated (arg * lengthOfCode) times.


s-lang, 30 bytes



1 5 6 7 8 9

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.