# I double the source, you double the output!

Your task, if you wish to accept it, is to write a program that outputs a positive integer (higher than 0). The tricky part is that if I duplicate your source code, the output must be double the original integer.

# Rules

• You must build a full program. That is, your output has to be printed to STDOUT.

• The initial source must be at least 1 byte long.

• Both the integers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).

• Your program must not take input (or have an unused, empty input).

• Outputting the integers with trailing / leading spaces is allowed.

• You may not assume a newline between copies of your source.

• This is , so the shortest (original) code in each language wins!

• Default Loopholes apply.

### Example

Let's say your source code is ABC and its corresponding output is 4. If I write ABCABC instead and run it, the output must be 8.

# Leaderboard

This uses uses @manatwork's layout.

/* Configuration */

var QUESTION_ID = 132558; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8349457; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
jQuery.ajax({
url: answersUrl(answer_page++),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
answers.push.apply(answers, data.items);
answers_hash = [];
answer_ids = [];
data.items.forEach(function(a) {
a.comments = [];
var id = +a.share_link.match(/\d+/);
answer_ids.push(id);
answers_hash[id] = a;
});
if (!data.has_more) more_answers = false;
comment_page = 1;
getComments();
}
});
}

function getComments() {
jQuery.ajax({
url: commentUrl(comment_page++, answer_ids),
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
answers_hash[c.post_id].comments.push(c);
});
if (data.has_more) getComments();
else if (more_answers) getAnswers();
else process();
}
});
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(-?\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
return a.owner.display_name;
}

function process() {
var valid = [];

answers.forEach(function(a) {
var body = a.body;
a.comments.forEach(function(c) {
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});

var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
link: a.share_link,
});

});

valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});

var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;

var answer = jQuery("#answer-template").html();
answer = answer.replace("{{PLACE}}", lastPlace + ".")
.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)
.replace("{{LINK}}", a.link);
answer = jQuery(answer);
jQuery("#answers").append(answer);

var lang = a.language;
if (! /<a/.test(lang)) lang = '<i>' + lang + '</i>';
lang = jQuery(lang).text().toLowerCase();

languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
});

var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);

langs.sort(function (a, b) {
if (a.uniq > b.uniq) return 1;
if (a.uniq < b.uniq) return -1;
return 0;
});

for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
.replace("{{LINK}}", lang.link);
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body { text-align: left !important}

#answer-list {
padding: 10px;
width: 290px;
float: left;
}

#language-list {
padding: 10px;
width: 290px;
float: left;
}

table thead {
font-weight: bold;
}

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/Sites/codegolf/all.css?v=617d0685f6f3">
<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><a href="{{LINK}}">{{SIZE}}</a></td></tr>
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
<tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr>
</tbody>
</table>

• @Mr.Xcoder Then I'll just have to include one in my own source. – steenbergh Jul 15 '17 at 17:55
• @Mr.Xcoder I think that you should have prevented reading your own source code. – caird coinheringaahing Jul 15 '17 at 18:09
• @Daniel Let's say your source is  (empty program) and it produces 5. If you double it, your source is  (empty program) and that produces 5 as well, no matter what you do. That being said, an empty program duplicated is still the empty program, and always produces the same output, except for the case where the empty program means something else (a random number generator, for example), which could not be valid anyway. – Mr. Xcoder Jul 17 '17 at 9:11
• This shouldn't be hard for esolangs that automatically dump the top of stack upon program termination. – MD XF Jul 18 '17 at 22:26
• @Rogem You must build a full program already implies that. – Mr. Xcoder Jan 16 '18 at 9:09

# Python 2, 33 bytes

print len(open(__file__).read())#


Try it online!

Try it doubled

# Python 3, 28 bytes

print(len(*open(__file__)))#


Try it online!

Try it doubled

## Explanation

This opens up the source code using open(__file__) and gets its length using len the # prevents any additional code from being read. When the source is doubled so is the length.

• Wow, I'm stunned... That's so brilliant! – Mr. Xcoder Jul 15 '17 at 15:24
• 32 bytes. Works by using append mode, setting the current position to the end of the file. tell() returns the current position in the file – Halvard Hummel Aug 29 '17 at 5:34
• @HalvardHummel Nice. However I have no intention of updating this answer. If you would like to post it on your own it is substantially different in my opinion. – Sriotchilism O'Zaic Aug 29 '17 at 5:44
• @WheatWizard That is understandable, I made a separate answer – Halvard Hummel Aug 29 '17 at 5:48

# Jelly, 1 byte

‘


Try it online!

I have no idea how this works, but apparently it does.

• That moment when you have no idea what you have written... – Mr. Xcoder Jul 15 '17 at 15:31
• Darn it, I just thought of this 8 minutes too late. – HyperNeutrino Jul 15 '17 at 15:40
• isn't this something to do with Jelly's implicit argument of 0 when called niladically? – Nick Clifford Jul 15 '17 at 17:45
• @nickclifford I didn't know about that, but that would explain it. – DJMcMayhem Jul 15 '17 at 17:47
• All links need an argument. If the first element of the chain is a nilad, its result becomes the argument and the link is executed monadically. If there is no leading nilad, 0 is used instead. – Dennis Jul 15 '17 at 20:03

# Google Sheets, 11 5 Bytes

Anonymous worksheet formula that takes no input and outputs into the cell which holds the formula

=4/(2


As a single formula this evaluates to a call stack that looks a little something like

=4/(2
=4/(2)
=4/2
=2
2


However when this worksheet formula is doubled this call stack evaluates down to

=4/(2=4/(2
=4/(2=4/(2)
=4/(2=4/(2))
=4/(2=2)
=4/(True)
=4/True
=4/1
=4
4


Of course, an implication of using this method is that once this is repeated more than once, at the third and all following iterations of the problem, the call stack will reach =4/(2=4) and thus evaluate down to =4/0 and throw a #DIV/0! error

-6 bytes by switching to algebra away from the =DIVIDE(4,2 formula

• Never expected Google Sheets would have use in code golf. Clever solution – hucancode Jul 17 '17 at 3:11
• @hucancode the really interesting bit about this is that because Excel throws an error if you exclude the trailing )'s this answer is the only Google Sheets answer that I've Seen that does not translate into an Excel answer – Taylor Scott Jul 19 '17 at 13:18

## C (gcc), 37 bytes

i;main(){putchar(i+49);}/*
i=1;//*///


The file does not contain a trailing newline.

TIO links: single, double.

• Can you please explain how this works? why would the comment ever be uncommented? – Blauhirn Jul 15 '17 at 20:29
• When you double the source code, the /* is commented out by the //, which means the following i=1 is uncommented. This is easier to see if you put the doubled version of the code in a syntax highlighter – musicman523 Jul 15 '17 at 20:50
• Whoa, a tentative definition trick. Nice. – aschepler Jul 18 '17 at 11:18

# 05AB1E, 2 bytes

Original

XO


Try it online!

Doubled

XOXO


Try it online!

Explanation

X pushes 1 to the stack.
O sums the stack.

• XOXO, nice solution. – Mr. Xcoder Jul 15 '17 at 15:36
• You did that on purpose, while you knew you could've also used 1O! – Erik the Outgolfer Jul 15 '17 at 19:00
• Where do you guys find these ridiculous languages? – DavidB Jul 17 '17 at 4:01
• @DavidB Usually, they write them. – Federico Poloni Jul 20 '17 at 6:56
• @DavidB Yes, people do invent languages for codegolf, and yes, they can get impressively low scores, but doing silly things like inventing a language after the challenge to solve it in 1 byte are disallowed, and programming in these languages is usually far from easy. – Esolanging Fruit Jan 10 '18 at 4:03

# Hexagony, 7 bytes

/)!@.).


Prints 1 regularly then 2 doubled.

### Expanded versions:

Regular:

 / )
! @ .
) .


Doubled:

  / ) !
@ . ) .
/ ) ! @ .
) . . .
. . .


The regular program follows the path: /)!.@ which increments a memory edge (all are initialised to zero) then prints its numeric value. The doubled program follows: /.)/)!@ which increments the edge twice before printing, instead.

• Wow nice work. I assume you found that by hand? Since 6 bytes is in brute force range, I thought I'd give it a go, and there's actually a 4-byte solution: [@!) (and some 570 5-byte solutions). Since you actually went to the trouble of finding a solution by hand, I'm perfectly happy for you to post the 4-byte solution. – Martin Ender Jul 16 '17 at 8:16
• If you're interested, here is the full list including the number that is printed: pastebin.com/TtRujjA4 – Martin Ender Jul 16 '17 at 8:24

# Python 2, 21 bytes

+1
if id:id=0;print 1


Try it online!

Doubled:

+1
if id:id=0;print 1+1
if id:id=0;print 1


Try it online!

• Crazily creative! Congrats! – Mr. Xcoder Jul 16 '17 at 7:50
• What if it is doubled with a linefeed inbetween? – yeti Mar 17 '18 at 2:45

# Braingolf, 1 byte

+


Try it online!

Now we're talkin'!

Outputs 20, or 40 when source is doubled.

## Explanation

+ is of course the "sum", "add" or "plus" operator, in Braingolf, however it has dyadic, monadic and niladic functions.

When there are at least 2 items on the stack, it's dyadic, and will sum the top 2 items of the stack.

When there is only 1 item on the stack, it's monadic, and will double the item.

When there are no items on the stack, it's niladic, and pushes 20!

Why does it push 20? Well because an empty Braingolf program simply prints a newline, and the ASCII value of a newline is 10, so I figured I'd make niladic + push 20 so it's like it's actually being monadic on the implicit newline (even though it isn't at all)

Therefore:

+   No input
+   Niladic sum, Push 20
Implicit output


And when doubled up:

++  No input
+   Niladic sum, Push 20
+  Monadic sum, Double top of stack
Implicit output


# Haskell, 26 18 bytes

main=print$0 +1--  Try it online! Doubled: main=print$0

### Doubled

clearTimeout((t=this).x),t.x=setTimeout(alert(${t.n=-~t.n}));clearTimeout((t=this).x),t.x=setTimeout(alert(${t.n=-~t.n}));

• I guess this would work also: window.i=++window.i||1; in the browser console. It ouputs 1. Browser refresh, window.i=++window.i||1;window.i=++window.i||1; ouputs 2. – Christiaan Westerbeek Jul 17 '17 at 13:13
• @ChristiaanWesterbeek True. But then it's a REPL answer (and you can actually just do this.i=++this.i||1;). – Arnauld Jul 17 '17 at 13:23
• I don't know what that means, REPL answer – Christiaan Westerbeek Jul 17 '17 at 13:26
• @ChristiaanWesterbeek REPL stands for Read-Eval-Print Loop. In that case, the final result is not explicitly printed by the code but by the shell it's running in (like the browser console). – Arnauld Jul 17 '17 at 13:31
• @ChristiaanWesterbeek (Actually, just +1 would work in REPL -- like this Python REPL answer does.) – Arnauld Jul 17 '17 at 13:33

# PHP, 30 bytes

Original

<?=strlen(file(__FILE__)[0]);#


Try it online!

# PHP, 60 bytes

doubled

<?=strlen(file(__FILE__)[0]);#<?=strlen(file(__FILE__)[0]);#


Try it online!

• Port of the Python solution? – Mr. Xcoder Jul 15 '17 at 16:57
• @Mr.Xcoder after your comment I have saw the python solution. It is the same way – Jörg Hülsermann Jul 15 '17 at 17:07
• Why not <?=strlen(file(__FILE__)[0]);# – Darren H Jul 15 '17 at 17:34
• @DarrenH I have not thinking about it – Jörg Hülsermann Jul 15 '17 at 17:45
• this is 23 bytes: <?=filesize(__FILE__);# - and doubled is 46 bytes. – hanshenrik Jul 23 '17 at 13:27