# 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

• 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

# Brainfuck, 25 bytes

Prints 50 characters, most of which are control characters.

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

"a"*15*$args[0] # Powershell, 2 This answer without the bonus is probably golfier though$?

Outputs;

True
• @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 – Jonathan Leech-Pepin Oct 7 '15 at 15:11
• @JonathanLeech-Pepin No - that won't work, either, for the same reason. See my corrected answer – AdmBorkBork Oct 7 '15 at 15:14
• @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. – Jonathan Leech-Pepin Oct 7 '15 at 15:26
• @JonathanLeech-Pepin Let's continue this discussion in chat – AdmBorkBork Oct 7 '15 at 16:21
• Also, if given no input, it should default to 2. – LegionMammal978 Dec 29 '15 at 14:08

s/^$/11/ s/.*/&&&&&/ s//&&&&&&&&/ s/.// 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
80
40
80
120
160
• 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. – 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"
1
'XXXXXXXXXXXXXXXXXXXXX'

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

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

# APL, -8 bytes

'*'⍴⍨17×{0::2⋄⎕}⍬

Explanation:

• {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
import"fmt"
func main(){fmt.Printf("%118d",0)}

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

package main
import("os"
"fmt")
func main(){i:=2
if len(os.Args)>1{fmt.Sscanf(os.Args[1],"%d",&i)}
fmt.Printf("%"+fmt.Sprintf("%d",i*145)+"d",i)}
• 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. – daniero Oct 10 '15 at 13:04

# Hassium, 55 Bytes

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

Output:

3.141592653589793.141592653589793.141592653589793.141592653589793.141592653589793.141592653589793.14159265358979

Run and see online here

• I thought extra whitespaces are not allowed? – 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:)

Explained:

? &DUP        ~ get some input; dup it
0 =           ~ if 0
[             ~ then
]             ~ fi
(             ~ 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 mb.xE2 Demonstration 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 print"J"x22 Using the lovely x operator, prints 22 Js. I may be able to find a shorter answer. # Python 2, 11-1-6 -11 bytes 'M'*input()*14 Prints 14 * input Ms. Requires a REPL environment. There may be a way to make it shorter, but at this point I doubt it. Changes • Saved 5 bytes by not using int(). • Saves 5 more bytes thanks to @cat and using a REPL environment. • the question doesn't say assuming a REPL environment is disallowed, so 'M'*input()*14 is shorter for 14 == -11 – cat Dec 17 '15 at 16:29 • @cat Thanks, I'll add that in now. – ASCIIThenANSI Dec 17 '15 at 16:42 • If no input is provided, you must default to 2. This does not. – isaacg Mar 30 '16 at 1:54 # MATLAB, 5 bytes a=123 Which displays a = 123 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. Hexdump: 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: Magnified 64x, with color labels: 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 Echo[16!] If I am correct, this should output: >> 20922789888000 with a trailing newline. # Gogh, 3 bytes 6GJ You can run it like this: ./gogh o '6GJ' Or without implicit output (4 bytes): 8GJ¡ You can run this using: ./gogh "" "8GJ¡" The inverted exclamation point outputs the TOS. ### Explanation 6 “ Push the integer literal 6 ” G “ Push a range (0, TOS] ” J “ Join the TOS ” # Python 2, 11 bytes print0*21 This outputs 21 zeroes and a newline. 000000000000000000000 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. (.O.NU.\!@O$..u

This maps to a cube with edge length 2

( .
O .
N U . \ ! @ O $. . u . . . . . . . . . Outputs 109998887776665554443332221110 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) Program: print(("a"):rep(40)) Output: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (Change 40 to 39 if newline is counted) Bonus: 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.) • Welcome to PPCG! Usually, our community does not like storing input in variables beforehand. It would be better accepted to read from STDIN. – GamrCorps Mar 30 '16 at 3:47 # Underload, 12 bytes (\/)a:*::**S Outputs (\/)(\/)(\/)(\/)(\/)(\/) Try It Online Explanation (\/) # 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 µa~Åm16. Outputs a 16 times. Simple enough. More detailed explanation: µ Begins reading a string a ~ Stops reading a string and stores it in the selected cell Å Command set 2 m Print the cell's value n times 16 . 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 • That's only 10 bytes, and you can use 'say' to cut down on two more (run with -M5.010 flag which is free) – Gabriel Benamy Oct 23 '16 at 18:44 # BASH, 19 bytes 54 bytes -25 bonus. Using the variable input for x repeats: #!/bin/sh a=$1;for i in seq 1 ${a:=2};do cat$0;done

#!/bin/sh
a=$1 for i in seq 1${a:=2}; do
cat $0 done 19 bytes for a simple sh script. #!/bin/sh cat$0 $0 • Personally I dislike backticks a lot, but it saves 1 char. – CousinCocaine Aug 4 '16 at 16:11 • DARN, "No file/disk/network io allowed", therefor I exclude this answer from the competition. – CousinCocaine Aug 4 '16 at 16:14 # Turtlèd, 8 bytes (non-competing) 15:[*,l] explanation: [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) x.nim(1) There are nine trailing spaces there. Conversely, when saved in areallylongfilename.nim, this is output: Traceback (most recent call last) areallylongfilena Newlines are also output in each example. Example usage:$ nim c length.nim
\$ ./length | wc -c
54

# 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

t[][sssssssssssssss]t[s][ssss]