# 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 Oct 2 '15 at 23:20
• Looks like the code snippet has to be modified to handle negative scores. 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

# HQ9+, 2 bytes

QQ


outputs

QQQQ


I think it is not forbidden here.

• It may not be forbidden, but it's not very inter... wait, how did it get eight upvotes? Oct 3 '15 at 16:37
• @JanDvorak Much as I dislike HQ9+, this to me is a creative use. This usage most likely wasn't envisioned when HQ9+ was created, which is more than can be said of most other Hq9+ programs. +1 from me. Oct 3 '15 at 16:50
• I didn’t even know that Q prints “the program’s source code”. I thought it just printed a Q. Well done for spotting the crucial difference! Oct 7 '15 at 17:14
• @LegionMammal978 Technically this is a constant output challenge, which means non-programming languages are allowed. Jan 16 '16 at 0:12
• This has 120 votes. 1,200 rep for typing QQ into an interpreter. Sep 23 '17 at 0:07

# Shakespeare, 768

Yeah, Shakespeare's not much of a golfing language. Outputs 1,536 spaces.

Rosencrantz and Guildenstern: A Series of Tedious Events.

Rosencrantz, a count of extraordinary determination.
Guildenstern, a spacy character.

Act I: The Long Conversation

Scene I: A Tortured Friendship

[Enter Rosencrantz and Guildenstern]

Rosencrantz:
You are a gentle, noble, valiant, loyal, loving companion.

Guildenstern:
You are nothing!

Scene II: Asking the Hard Questions

Rosencrantz:

Guildenstern:
You are as fair as the sum of yourself and a daisy. Are you as
daring as the sum of a big, bold, fiery, feisty, rough, rowdy,
large, yellow, vicious, hairy, wild, scary, long-tailed,
sharp-clawed, small-eared lion?

Rosencrantz:


# Edit: 256

Okay, I'll actually golf it. Note that the above does not compile in any existing Shakespeare implementation because I wrote it painstakingly by hand (but am prepared to defend its correctness.)

The below translates to C with one warning in spl-1.2.1, and outputs 512 spaces:

Ummm.Ajax,1.Puck,2.Act I:I.Scene I:A.[Enter Ajax and Puck]Ajax:You old old old old old cow.Puck:You are zero!Scene II:B.Ajax:Speak thy mind.Puck:You are the sum of you and a red cat.Are you as big as the square of me?Ajax:If not, let us return to scene II.

• I'll +1 if you actually golf this. Oct 4 '15 at 6:47
• What manner of whitchcraft is this? I didn't even know such thing existed... Oct 5 '15 at 18:23
• woah, you golfed it. Holy havens. Oct 21 '15 at 12:49
• @Malavos I was just joking about the way you misspelled witchcraft, sorry -- both what and which are probably ok
– cat
Oct 21 '15 at 12:55
• No, I ask for your forgiviness if I sounded offensive or defensive. I was just making a reference to Futurama! :) On a serious note, I'm still surprised by this answer. We need more of those on the site. Oct 21 '15 at 13:39

# Recall, 17 bytes

................!


16 NOOPs. Then the debugger ! is invoked and dumps the memory to the console. The memory is empty, but the header is 34 bytes long:

-- STATE DUMP --
----------------


Try it here.

• This is one of the cooler answers IMO.
– cat
Oct 20 '15 at 23:35
• Creative answer. These are my reasons to visit codegolf. Apr 28 at 11:15

# Mathematica REPL, 1 byte

#


Prints #1.

• The question says to "write a complete program"; this is just a REPL snippet. Dec 29 '15 at 14:19

# CJam, -17 bytes

r2e|i8,*


The source code is 8 bytes long and qualifies for the -25 bytes bonus.

Try it online in the CJam interpreter.

### How it works

r         e# Read a token from STDIN.
2        e# Push 2.
e|      e# Logical OR; keep the token if it's not empty, 2 otherwise.
i     e# Cast to integer.
8,   e# Push [0 1 2 3 4 5 6 7].
*  e# Repeat the array the corresponding number of times.

• Crap. Well done. Oct 3 '15 at 0:22
• How is it negative bytes? Oct 5 '15 at 4:49
• @NickT 8 bytes (source code) - 25 bytes (bonus). Oct 5 '15 at 4:51
• You can save several million copies of it if you're running out of disk space. Mar 19 '16 at 14:42
• No, I think metadata would make it positive Mar 19 '16 at 22:12

## Python 2.6, 10

print-.1


Prints -0.10000000000000001, which is 20 chars.

Note that the string repr shows more precision. print-.1 just gives -.1, and print.1/3 gives 0.0333333333333 for only 13 digits of accuracy.

• This no longer works in Python 2.7 or 3.1. Oct 3 '15 at 1:27
• @AndersKaseorg So repl.it is wrong, then? Oct 5 '15 at 18:17
• @mbomb007 Apparently. GitHub suggests that’s hardly the only thing it’s wrong about. Ideone agrees with CPython. Oct 6 '15 at 2:01
• Same comment as for your other answer: doesn't this print a trailing newline, giving 21 bytes of output? Oct 27 '15 at 16:20
• You mean print+.1? Apr 13 '17 at 14:16

# Seed, 10 bytes

4 56111240


This compiles to the Befunge program (found by brute force)

9k.@


which produces the following 20 bytes when run (tested in CCBI, note the trailing space):

0 0 0 0 0 0 0 0 0 0


Being unfamiliar with Befunge 98, I had to double check the spec a few times for this one:

• k seems pretty broken to me, executing one more time than intended due to the IP moving into the repeated instruction
• Befunge 98's stacks have infinite zeroes at the bottom
• . outputs as a number, followed by a space
• .... I....just....can't. Oct 5 '15 at 18:22

# R, 3 2 bytes

### Code

!0           # NOT FALSE


Outputs

TRUE


Wow, finally R, finally.

It seems that {} work too, it outputs NULL

## Bonus 33 16 bytes:

### Code

rep(1,number*16)


Outputs

# if number is not defined
> rep(1,number*16)
> Error: object 'number' not found     # output is 32 (or 2*16) bytes long error

# if number is defined
> number = 3
> rep(1,number*16)                     # output is 16*number bytes long
> 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

• I hope using the name "number" for the variable is not equivalent to " adding unnecessary whitespace to the source code" Oct 7 '15 at 19:33

# JavaScript, 2 bytes!

Even shorter than the 3 bytes solution:

!0


Returns true after running.

• You should note that this only works in a REPL environment Apr 30 '16 at 22:30
• If the \n following the print counts as a byte, one could simply use 0 or any other single number. Aug 12 '20 at 2:18
• I did 3E5 on my first one, but thought repl was cheating. Mar 22 at 18:27

# Matlab, 8 bytes

1234;'5'


Output:

The output contains newline, ans =, newline twice, space four times, '5', newline, so 16 bytes.

• Let's hope nobody has format compact as default :) Oct 3 '15 at 8:47
• @sanchises :-) Yes, that depends on how Matlab's preferences have been set. But format loose is the default preference Oct 3 '15 at 9:19
• How about 123;4? Is three bytes shorter=) Mar 30 '16 at 10:30
• @flawr Good idea! Post it yourself! Mar 30 '16 at 10:32
• Nope, way too much inspired by your answer=) Mar 30 '16 at 10:33

## Python 2, 11

printid*1


Print the string representation of the built-in id, which is 22 chars:

<built-in function id>


The *1 is to get the code to 11 chars. You could also do print id;00.

More boring alternative 11's are:

print'1'*22
print 9**21

• I've been playing around with complex numbers, but unfortunately print.8/-9j is one char short Oct 3 '15 at 15:21
• Don't these print a trailing newline, bringing the output's byte count to 23? Oct 27 '15 at 16:01
• @MartinBüttner That rule was edited in later, but changing it to print id,;1 suffices to suppress the trailing newline. It doesn't add a trailing space either.
– xnor
Oct 27 '15 at 21:29
• @xnor print 9**21 doesn't work. It's 21 characters. print 9**23 works though Apr 13 '17 at 7:42

# dc, 10 - 25 = -15

2?A*Ar^1-n


Takes a blank line for "no input".

Calculates 10 ^ (10 * n) - 1, where n is the input, or 2 if input is empty. Prints a string of 9s of the required length.

• 2 push 2 to the stack in case input is empty
• ? push input to the stack
• A push 10 to the stack (dc has shortcuts A-F for 10 - 15)
• * pop twice and multiply (multiply input by 10)
• A push 10 to the stack
• r reverse top two stack elements
• ^ exponentiate 10 ^ (10 * input)
• 1- subtract 1 from the top of stack
• n print with no newline.
• dang, that is so clever. And lucky with the code length there :) But maybe you should add a small explanation for the uninitiated. And I think newline counts, so you should probably use n instead of p. Oct 3 '15 at 11:13

# Brainfuck, 14 bytes

+++++++[....-]


This is a little mathematical exercise. Let's denote the number of + characters in the code by a, and the number of . characters by b.

The code outputs a*b bytes, with values from a down to 1 (these are non-ASCII bytes, but it seems OK according to the spec). The code's length is a+b+3. So we have

a*b = 2 * (a+b+3)


Trying different values for a and b, we see that the minimum for a+b+3 is achieved for

a = 4       or       a = 7
b = 7                b = 4

• A veteran brainfuck programmer will spot the +[[>....]-<<+] option. Apr 5 '19 at 14:29
• @orthoplex When I read your comment I immediately portmanteau'd brainfuck and programmer: brainfucker
– Poke
Jun 7 '19 at 20:36

# gs2, -18 bytes

CP437: W↕0!↨.2

Hex dump: 57 12 30 21 17 2e 32

W reads numbers from STDIN into a list. ↕0 appends a 2 to the list, and ! extracts the first element. Then ↨. (the list [0,1,2,3,4,5,6]) is repeated (2) this many times.

This is very similar to Dennis's CJam answer -- gs2 just combines r and i into one byte.

Note: I had to fix a bug in the gs2 implementation for this to work: previously, each program had a hidden newline appended to its output, which was entirely unintentional. It only surfaced after I tried to solve this program (the language was designed for anarchy golf, which ignores trailing newlines in all problems), and I only pushed a fix to master just now, so feel free to take this answer with a grain of salt.

• First GS2 answer I've seen that doesn't have any card suit characters! Apr 30 '16 at 22:32

# TI-Basic, 3 bytes

1ᴇ5


Prints 100000.

• Actually, I think the newline would count, so you can just do 0 for 1 byte. Oct 3 '15 at 22:58
• How about ᴇ3? And @lirtosiast, since TI-Basic doesn't have newlines I'm skeptical about that. Aug 15 '17 at 23:36

# Pyth, 10 9 - 25 = -16

-1 by Dennis

**N9?zvz2


Prints [input]*9 quote characters, or 2*9 if the input is empty.

isaacg has a shorter answer here

# Pyth, 1 byte

T


Prints 10. It's a built in variable that initializes to 10.

• It would be useful if .x worked with errors. Is there a justification for why it doesn't? Oct 3 '15 at 0:16
• My best guess is that Q causes Pyth to eval the input before the actual code is executed. **N9.xvz2 works as expected, but it's not shorter than **N9?zvz2. Oct 3 '15 at 17:13
• Any trailing newline is included in the output's byte count. T outputs 10 and a newline. Use d, it's a space which gets a newline appended Sep 23 '17 at 0:10

# Perl 5, 16 bytes - 25 = -9

$_ =$]x($_*2||4)  This is an oddball approach to the problem. Run with the -p command line argument. I saw a Perl answer below that used a special variable to print more text - and thus shorten their byte count. So I used a much more verbose special variable. It prints 8 characters with a 2 character variable name. Thus, with a byte count of 16 (padded with one whitespace character to make it 16), it prints 2 *$], where $] is the Perl version printed as 5.xxxxxx, dependent upon your Perl version. Without input it prints it four times, equaling 8*4 or 32, which is double the byte count of the code. I love Perl. • I think this fails for empty input. Per the rules, if no input is provided, the multiple should default to 2. Oct 3 '15 at 0:12 • @AlexA. Damn, I missed that. New to code golf. Edit incoming, but my answer has a lot of characters now because I have no idea how to do this more creatively in perl :( Oct 3 '15 at 1:00 • Hey there, a few more tips that might help you here, by default in a program script, pop and shift work on @ARGV (in a sub they work on @_) so you could do something like $n=pop||2 to get the first code block down, and you have ;} at the end, which can almost always be just } to save another. Something that might help you save more chars is the string repetition operator x, consider print 1x20 or something along those lines... :) Hope that helps! Oct 3 '15 at 8:07
• @DomHastings Man, thanks! I got it down to 2 bytes total because of your help :) Thank you very much for your suggestions. Oct 3 '15 at 16:12
• I think you can shorten it to this print"n"x(21*pop||42). Run on the command line with perl -e'print"n"x(21*pop||42)' 3 | wc -c Oct 6 '15 at 16:33

## Macaroni 0.0.2, 23 chars

print tobase pow 32 9 2


Prints 329 in binary, which happens to conveniently turn out to be 46 characters long (it's 1000000000000000000000000000000000000000000000), without a trailing newline.

# C, 27 25

main(){printf("%50f",0);}


Thanks @Titus for knocking off 2 bytes

# And for my non-competing16 byte solution in C, go here: https://codegolf.stackexchange.com/a/111330/16513

^I say non-competing because the error code could possibly depend on your compiler, Also note I'm using GCC in that solution. Also I'm not certain if it breaks rule 1 or not, I think it probably does so I went ahead and labeled it non-competing

• I do not think that counts as a valid C program but main(){printf("%0.XXf",0);} works. Oct 4 '15 at 14:59
• @Zereges No, C has the "implicit declaration" rule that usually lets you use stuff without the proper #include. The compiler will emit a warning, and it will sometimes crash, but it will usually work. Oct 5 '15 at 7:42
• @AlbertRenshaw Also, I do not think it works here. Oct 5 '15 at 11:49
• Note that 27*2 != 38. Oct 5 '15 at 18:27
• @Zereges. This code does not exhibit undefined behaviour. The "implicit declaration" and "implicit return type" features are deprecated in recent standards, but their usage is still permitted and results are well defined. There are circumstances in using such features causes undefined behaviour, but this code does not involve those. Oct 6 '15 at 8:28

# JavaScript, 4 bytes

+1/0


Prints Infinity

I think this is the shortest possible JS solution without ES6 :P

• What version of NodeJS do you have? This doesn't work with mine. Oct 4 '15 at 14:04
• This also works on Firefox console. Oct 5 '15 at 7:29
• The trailing newline should be included in the output length. Oct 7 '15 at 1:21
• Node.js v0.10.40 doesn't print anything at all because there's no print command. Do you have a different version of Node.js or does this only work in a shell that prints the evaluation of a line? (in which case I don't think this answer would be valid). Oct 7 '15 at 8:15
• What about !0? Sep 21 '16 at 1:35

# V, 2 Bytes

4é


This outputs

ÿÿÿÿ


Try it online!

Explanation

This is a really hacky answer, and it works by abusing the internals of V. Essentially how it works is that ÿ is a command in V that signals the program is over, and any pending commands must complete. Otherwise, some implicit endings would not work, and the interpret would hang more often. This command is automatically sent several times at the end of the program, and most of the time has no effect on the output.

é is a command that inserts a single character. However, it does it by grabbing a raw byte, so it doesn't interpret ÿ as "end", it interprets it as "this is the character you need to insert." 4é makes it insert this character 4 times instead of one.

# bash, 11 bytes

Here's a pleasingly ironic usage of a data compression tool :) ...

gzip -f<<<2

Here's a hex dump of the output (22 bytes)...

0000000: 1f 8b 08 00 e3 ce 32 59 00 03 33 e2 02 00 90 af  ......2Y..3.....
0000010: 7c 4c 02 00 00 00                                |L....

• This outputs 22 bytes of "extended ASCII" (eg. 8 bits per character). This seems to meet the OP's definition of ASCII if you read the comments on the Question post. Jun 3 '17 at 16:06
• On TIO I got 16, but on my linux machine, I got 34 Sep 23 '17 at 0:27
• @StanStrum, I don't know what TIO is, but that 34 under linux is odd. Perhaps you have gzip aliased to use different switches to normal? Sep 23 '17 at 9:31
• I don't know if that's the case, but that does seem odd. I'll try it on some LiveCDs to see if I messed it up with one of my programs @Wossname Sep 23 '17 at 14:19
• I'm not that guy, and I won't take advantage of my newly earned 129 rep tyvm. I'll see if I can make a version that works on my Linux installation Sep 23 '17 at 19:19

# JavaScript ES6, 33 - 25 = 8

(a=2)=>Array(a*33).fill(0).join


Try it online!

• I can't seem to make this code run on console. Is it right? "Uncaught SyntaxError: Unexpected token =>" Oct 5 '15 at 18:24
• @Malavos you need an es6 compliant browser such as the latest Firefox. Chrome doesn't support default args afaik Oct 5 '15 at 19:00
• I'm using UCBrowser, but that's right! It's based on chromium and gecko anyway. Tried it on nightly, got "000000000000000000000000000000000000000000000000000000000000000000". Nice! Could you explain your code for me? I'm a newbie. Oct 5 '15 at 19:06
• @Malavos The hardcoded 33 is actually the length of the code. It creates a new array with length 33*a where a is the input parameter defaulting to 2 as per the OP, fills it, and returns a joined string. Oct 5 '15 at 23:17
• By creating your array with one extra element you can fill with the join Arrary(1+a*<length>) and join0 Oct 6 '15 at 17:27

# dc, 19 - 25 = -6

2?19*[1n1-d0<l]dslx


Takes a number (2 is pushed to the stack as backup) and multiplies it by 19. Prints a 1 (no newline) and decrements the number. Loops while the number is greater than 0.

# C++, 80 bytes

#include<iostream>
int main(){int i=0;while(i<20){std::cout<<&i;i++;}return 0;}


note the newline character is two characters. (if you don't want it to be, change i<20 to i<=19 to get back to the same byte count.)

Sample output (will change every time)

0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C0088FA0C


same 8 character memory address 20 times.

• Some golfing hints: a for loop is shorter than a while loop and lets you drop the braces, it's slightly cheaper to use cstdio and just printf a string, and you don't need to return anything.
– Luke
Oct 4 '15 at 4:31
• You can strip your approach to 63 bytes: #include<iostream> int main(){for(int i=10;--i;)std::cout<<&i;} But there is already a shorter answer with a slightly different approach. May 31 '19 at 10:17

# CJam, -9

q_,{i}{;2}?G*'X*


# Explanation

• q_,

Reads the entire input and pushes it, then pushes the length.

• {i}{;2}?

If the length of the input is over zero, convert it to an integer. Otherwise, pop the input and push 2.

• G*

Pushes 16 (the program length), then multiplies it by 2 if there is no input, or by the input.

• 'X*

Pushes X and multiplies it by the top of the stack.

• @ThomasKwa Whoops. Updating in a sec. Oct 2 '15 at 23:43
• The comma is not necessary, however you can avoid the "if" altogether if you do a logical "or": q2e|i will give you the number you want Oct 3 '15 at 16:46
• Also you could use S instead of 'X, the only issue is that the output will not be visible until you select it (well, if you run it offline and redirect to a file, it's not a problem) Oct 3 '15 at 16:47
• Uh.. nevermind, I just saw Dennis's answer now :p Oct 3 '15 at 16:53
• Even with the conditional, you can shorten this. You don't need to calculate the length, since an empty string is already falsey. You also don't need to pop the empty string off the stack, since it does not contribute to the output. Which also allows yo to avoid the braces for the else branch. I came up with this before I looked at any of the answers: r_{i}2?SB**. Oct 3 '15 at 18:14

# ><>, 19 + 2 (-v flag) - 25 = -4 bytes

l?!2f4+*v
-1o;!?::<


test it here!

Thanks Cole and Sp3000

First checks the stack length, if it's 0 put 2 on the stack. Multiplies it by 21 (code length), then outputs the unicode representation of that number and decrements it by 1, loops until 0. (you'll have to inspect the output to see the characters, since the browser won't display them)

• Yeah, sorry to ruin your answer (but it is shorter than mine, if that makes you feel better). Edit: whoops hit enter too soon, your entry as it stands right now is not valid per the rule "You can assume that n will always be a positive integer. If no input is provided, n must default to 2." I also think it might print one too many characters (It goes from 14 to 0 which is 15 characters by my count, not 14). If I'm correct, l0=?2f6+*v as the first line and 1-::0=?;o> as the second should make it right.
– cole
Oct 3 '15 at 0:05
• Hm, not sure what you mean. It shouldn't print 0 in any case. Putting a 2 as the initial stack outputs (EDIT: stuff i can't paste) which, at least using this char counter, is 28 chars. Oct 3 '15 at 0:16
• I understand what you're saying now. I interpreted "Your program can optionally take a number, n, as input" meaning that if the input would be 2. I'll edit the answer, thanks! (also i can save some by using a string instead of numbers) Oct 3 '15 at 0:32
• Happy to help, especially if it's ><>.
– cole
Oct 3 '15 at 0:47
• ?! is usually better than 0=? Oct 4 '15 at 2:59

# JavaScript (ES5), 68 bytes - 25 bonus = 43

alert(Array(1+(+prompt()||2)).join(document.scripts[0].textContent))

(in case your browser won't allow for the snippet to run for security reasons, try this fiddle http://jsfiddle.net/thePivottt/c3v20c9g/ )

This script only works in a browser following at least DOM3 (with Node.textContent) and ECMAScript 5 (or perhaps an older version). I tried to make is as standard conforming and compatible as possible. It also assumes that the script is in the first script element of the document.

It actually concatenates multiple copies of the script itself, which is pretty awesome. Note that the snippet tool on SE puts extra whitespace around the script. We could ignore that whitespace with .trim() but I don't find it necessary considering the program is perfect without SE's meddling. Just save this HTML5 file if you want to see it run perfectly.

<!DOCTYPE html>
<html>
<title>Minimalist HTML5 page</title>
</html>


This script uses prompt and alert because console.log is not part of any standard, even if most modern browsers use it. If the number of repetitions passed is not a valid number or is empty, it defaults to 2. If the input is a decimal number, the program crashes due the the invalid array length.

The code uses a few interesting features of JavaScript:

• Array(1+(+prompt()||2))

• Array(INT) creates an Array of INT cells.

• +prompt() takes an input and turns it into a number. If we passed the input as a string, the Array function would simply wrap it in a one-element array.

• +prompt()||2 returns the input if it is truthy, else it returns 2.

• This whole code creates an array of N empty elements, where N is one more than the amount of repetitions asked.

• .join(document.scripts[0].textContent)

• The array's join(STRING) method creates a string by concatenating all the cells, putting the provided STRING between values. In this program, there are N+1 empty elements in the array, or exactly N in-between spots. The result will be a string containing N times the provided STRING.

• document.scripts[o] is the first <script> element of the document.

• The textContent of Node instances returns the whole text found inside them and their child nodes, including scripts.

• Note that if you use ES6's str.repeat and still output the code itself, it brings the score down to 26, but it's a bit too boring :P Oct 5 '15 at 1:36
• Erm, I don't know where that 26 came from, now I get 33. I should probably get some sleep. Oct 5 '15 at 4:13
• Note that some browser settings may prevent the use of prompt on a snippet. You might have to save it to run it. Oct 20 '15 at 13:02

# Julia, 42 bytes - 25 = 17

print("@"^42((r=readline())>""?int(r):2))


This reads a line from STDIN using readline(). If it's empty, i.e. no input has been provided, then n is defined to be the input converted to an integer. Otherwise n is 2. We then print 42​n @s to STDOUT.

# Perl, 18 - 25 = -7

print$=x(<>*9||18)  The special variable $=, a.k.a. $FORMAT_LINES_PER_PAGE, begins its life as 60, and therefore only needs to be duplicated half as many times as byte output needed. • I had a very similar answer of: print$=x9x(pop||2) nice! Oct 3 '15 at 8:54