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

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 COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 8349457; // This should be the user ID of the challenge author.

/* App */

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

}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
});
comment_page = 1;
}
});
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
});
else process();
}
});
}

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

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

function process() {
var valid = [];

var body = a.body;
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],
});

});

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;

.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)

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)
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body { text-align: left !important}

width: 290px;
float: left;
}

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

font-weight: bold;
}

table td {
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>

</tbody>
</table>
</div>
<div id="language-list">
<h2>Winners by Language</h2>
<table class="language-list">
<tr><td>Language</td><td>User</td><td>Score</td></tr>
<tbody id="languages">

</tbody>
</table>
</div>
<table style="display: none">
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
</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
• It only needs to work when doubled once? We don't need to support n many doublings? – Cody Gray Jul 16 '17 at 8:36
• @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

## Keg, 2 bytes

This indeed works. (Works in the old TIO version, I don't know which version is this)

1+


## A version that I can understand, 4 bytes

1(+)


Explanation:

1#    Push 1 onto the stack
(+)# Add the whole stack together

• This probably has something to do with why it works. I can't quite tell what the stack is doing, though, because TIO seems to be running an older and significantly different version of Keg.py where line 67 is return self.content.pop(). – Unrelated String Sep 13 '19 at 3:08
• @UnrelatedString, I haven't asked Dennis to update Keg on TIO yet because we're still testing to see that I haven't broken everything by implementing functions – Lyxal Sep 13 '19 at 22:46

# Python 2, 27 bytes

+7
try:_
except:_=7;print _


Try it online!

Try it doubled!

# Whispers v2, 23 bytes

+1
> 1
>> Output 3
>> 1


Outputs 1 normally and 2 when doubled.

## How it works

### Normal

Whispers only recognises lines that match one of a certain set of regexes. In the normal version, this reduces the program down to

> 1
>> Output 3


(i.e. the first and last lines don't match any regexes). The program then runs the last line, >> Output 3. This calls the 3rd line and outputs the result. However, as the reduced program only has 2 lines, this indexes modularly, returning the $$\3 \mod 2\$$th line (i.e. the first line), > 1. This is a basic nilad line which returns $$\1\$$, which is then outputted.

### Doubled

The doubled program is

+1
> 1
>> Output 3
>> 1+1
> 1
>> Output 3
>> 1


Removing lines which don't match any regex, we get

> 1
>> Output 3
>> 1+1
> 1
>> Output 3


Again, the last line is run, telling the program to output the result of line 3. This time however, we do have a line 3 to output: >> 1+1. This does return $$\2\$$ but not because it evaluates $$\1+1\$$. Rather, it adds the value of line 1 to itself, which happens to be $$\1\$$.

Interestingly, this means that by changing > 1 to > n where $$\n\$$ is any number, the programs output $$\n\$$ and $$\2n\$$. For example

+1
> π
>> Output 3
>> 1


outputs $$\\pi\$$ normally or $$\2\pi\$$ when doubled

# ><>, 24 20 bytes

\0r+n;
"

"
0
8
p
1



Try it online!

Uses the same trickery as my original 24 byte answer, just outputs 1 and 2 instead of 2/4.

\0r+n;
"

"
0
a
p
1
1
+


Try it online!

And try the double!

This starts at the \, diverts code execution down, does its trick*, pushes two 1's, then wraps around again. It hits the \ again, but from a different angle now, so the 0r+n gets executed and ; terminates the program.

(*) Note that the trick is to alter the source code by turning the instruction at 0, 10 into a space instead of a \ when the code is doubled.

When the code hits n; (print number and quit), the top of the stack is either 2 or 2, 2. In each case, a 2 gets printed, So we need to add 2 and 2 in case of the double source code, but we don't have a second stack item on the regular run. This is solved by 0r: push a zero and reverse stack. We now either sum 2 and 2 and ignore the (now bottom) 0, or we add 2 and 0.

# Vim, 5 bytes

i0<esc><C-a>:


Since V is backwards compatible, you can Try it online! or Try it doubled!

# Carrot, 4 bytes

2^F*


Outputs 2 normally and 4 when doubled.

Explanation normal:

2 //Input on the stack
^ //Convert to operations mode
F //Convert stack to float mode
* //Multiply stack by an empty argument (don't do anything)
//Implicit output of stack


Explanation doubled:

2  //Input on the stack
^  //Convert to operations mode
F  //Convert stack to float mode
*2 //Multiply stack by 2
^  //Convert to string stack mode
F* //Place the literal "F*" onto the string stack
//Implicit output of float stack


In Carrot there are three stack modes: string, float and array. Only the current stack modes stack is output at the end of the program.

# TI-Basic, 4 bytes

Fairly simple. I'm wondering if there are many alternate solutions.

1:2Ans       --> prints 2
1:2Ans1:2Ans --> prints 4


Alternate solutions

1+0 <-- 3 bytes based on @alexanderbird's answer

• what's wrong with (2 ? – Oki Sep 10 '17 at 18:36
• @Oki Nothing? I just didn't consider that. Mind if I change my answer to add that one? – Timtech Sep 11 '17 at 16:32
• i don't mind. tough your solution is much fancier – Oki Sep 12 '17 at 11:27

# Java, 121 bytes

### Original Code:

class A {static int n=1;public static void main(String[]a){System.out.print(n);}}/*
class B extends A{static{n++;}}//*///


### Duplicated Code:

class A {static int n=1;public static void main(String[]a){System.out.print(n);}}/*
class B extends A{static{n++;}}//*///class A {static int n=1;public static  void main(String[]a){System.out.print(n);}}/*
class B extends A{static{n++;}}//*///


Technically you have to run the main method of A the first time, and of B the second time. Still, it's one program.

• You can save a byte when you remove the whitespace class A { – Edwardth Jul 19 '17 at 14:51

# R, 2 bytes

+T


Never expected to codegolf this much in R. Due to the +, R changes the T for a numeric, using 1 as default.

# Klein, 5 + 3 = 8 bytes

\+@
2


The single program puts a two on the stack and attempts to add it. There is nothing to add so it is a noop and outputs 2. In the doubled program the \+@ section is not encountered but we do hit an additional 2 meaning that when we add again we add two 2s instead of a 2 and a zero. This results in 4. 2 can be replaced with any single digit number and this will still work, + can also be replaced with a * as long as we keep the 2, and \ can be replaced with a /.

# PHP, 4847 43 bytes

<?php ob_end_clean();ob_start();echo++$i;?>  Try it online! Result: 1 There's 2 PHP answers on here already, one of them looks like a port from Python and the other one breaks the error rule imo, so there's my shot at it. Doubled: # PHP, 9695 86 bytes <?php ob_end_clean();ob_start();echo++$i;?><?php ob_end_clean();ob_start();echo++$i;?>  Try it online! Result: 2 Explanation: ob_end_clean() once called, turns off the ob_start(). However, ob_end_clean will only clean items that started within the ob_start(). So to counter act this, we clear it first, run ob_start() then execute our counter. • Welcome to PPCG! I believe you can remove some newlines (after the semicolons) to save some bytes. – Stephen Aug 8 '17 at 13:14 • Good spot, thank you :) And thanks for the welcoming! – IsThisJavascript Aug 8 '17 at 13:23 # k, 2 bytes *2  Try it online! A "monadic" (one argument) * means "first", and a dyadic (two argument) * is multiplication. Therefore *2 is seen as "the first element of a list containing 2", which is 2. *2*2 first evaluates 2*2, which is 4, and then evaluates *4, which is 4. ## Perl, 15 bytes ++$_,exit print


Try it online!

Doubled:

++$_,exit print++$_,exit print


Try it online!

Increments $_ to 1 in the first instance, print outputs $_ by default, and we pass that as an argument to exit. When doubled, print explicitly outputs ++$_ which is now 2. # Carrot, 5 bytes ^F+1  Explanation: ^ --- Stack mode F --- Convert to float +1 --- Add 1 to the previous result <space> -- I have no idea  # Brian & Chuck, 15 bytes >>.>?2<<<?1 !>.  >>.>?2<<<?1 !>.>>.>?2<<<?1 !>.  Try it twice! This was my first attempt at learning Brian & Chuck. I took a short break after writing this answer and I've forgotten most of how it works. It relies on the facts that: • Chuck's 4th value is zero in the single program and non-zero in the double • . is a no-op in Brian's instructions, but prints in Chuck's instructions • In the double program, Brian's instructions are appended to Chuck's, but Chuck's are ignored because they're on the 3rd line. # Ly, 6 bytes 1&+s>l  Try it online! breakdown Command Operation stack content cell 1 push 1 1 &+ push sum of the stack 1,1 s pop to backup cell 1 1 > next stack 1 l push backup cell 1 1 implicit output of stack - or second execution: 1 push 1 1,1 1 &+ push sum of the stack 1,1,2 1 s pop to backup cell 1,1 2 > next stack 2 l push backup cell 2 2 implicit output  # Cubix, 4 5 bytes Of course as soon as I look at it again this presents itself. Not as nice as the previous, but shorter. ))O@  Try it online!  ) ) O @ . .  Increment, output and exit. ))O@))O@  Try it online!  ) ) O @ ) ) O @ . . . . . . . . . . . . . . . .  Increment twice, output and exit # TI-BASIC, 2 bytes 2!  There are also 5 more solutions, of equal or greater length. (2 abs(2 int(2 iPart(2 round(2  These all work on the same principle. Something evaluates to 2, and twice it is merely 2*2. • You should consider changing your formatting to have your solution in a separate code block prior to your outputs for both the singlet and doublet forms – Taylor Scott Sep 10 '17 at 19:13 # Bash + coreutils, 43 bytes x=$(history|cut -c 8-|tail -1);echo ${#x};#  # Explanation Outputs the length of the last command entered. Uses the same concept as the Python and PHP solutions to prevent execution of any further copies (finishes with a comment marker, so anything after it is ignored). Length of the command will be doubled when it is written twice, hence the output. • Can't you simplify this to echo${#0};#? – Neil Jul 15 '17 at 19:12
• i dont know about the above comment, but tail -n 1 can be shortened to tail -1 – phil294 Jul 15 '17 at 20:00
• @Neil I tried that but echo ${#0};# outputs 4 and echo${#0};#echo ${#0};# also outputs 4 – Darren H Jul 15 '17 at 20:44 • @Blauhirn nicely spotted, thank you – Darren H Jul 15 '17 at 20:44 • @Neil That would output the filename next to the count. You need to use a pipe like wc -c <$0 # – Richard Jul 17 '17 at 14:35

# Wumpus, 6 bytes

$@1$O+


Try it online!

Doubled:

$@1$O+$@1$O+


Try it online!

The first program pushes 1, adds the top two items on the stack (the 1 and an implicit 0), reflects off the end of the line, outputs and exits.

The second program does the same, except it adds two 1s to the stack, meaning it prints 2 and exits. This works for any number from 1-9.

A shorter solution may exist that takes advantage of two lines making the pointer bounce differently.

# ///, 20 bytes

Prints 1:

/\\1\//\/1\/2\/\//\1


Try it online!

Duplicated prints 2:

/\\1\//\/1\/2\/\//\1/\\1\//\/1\/2\/\//\1


Try it online!

# How it works

• The initial substitution /\\1\//\/1\/2\/\// (in both versions) searches for the string \1/ in the remainder and replaces it by /1/2//.
• In the single program there is no such string, and nothing is replaced. The program is now reduced to the final \1, which prints a 1.
• In the duplicated program \1/ crosses the boundary between the copies.
• After substituting, the remaining program becomes /1/2//\\1\//\/1\/2\/\//\1, which is the substitution /1/2/ followed by the single program.
• This substitution then replaces every 1 in the single program by 2, giving /\\2\//\/2\/2\/\//\2.
• This then runs pretty much like the single program does, except for printing 2 instead of 1.
• The normally redundant \ before the final 1, and the corresponding \\ in the initial substitution, are needed because without them, the substitution would be applied again to the /1/2/ result, causing an infinite loop.
• Was just thinking about doing a /// submission, but it looks like you beat me to it! – Esolanging Fruit Feb 12 '18 at 4:17

# Momema, 12 bytes

00 1+1*1-8*1


Try it online! This outputs 1.

Try it doubled! This outputs 02.

## Explanation

The ungolfed form of the singular program 00 1+1*1-8*1 is

0   0     # set the 0th cell to 0 (this has no effect).
1   +1*1  # set the 1st cell (initialized to 0) to itself plus one (i.e. 1).
-8  *1    # output the value of the first cell as a decimal (1).


The ungolfed version of the doubled program 00 1+1*1-8*100 1+1*1-8*1 is

0   0     # set the 0th cell to 0.
1   +1*1  # increment the 1st cell.
-8  *100  # output the value of the 100th cell (0).
1   +1*1  # increment the 1st cell.
-8  *1    # output the value of the 1st cell (2).


This submission hinges on Momema's syntax: in particular, it allows leading 0s in a numeric literal to be parsed as separate numbers. This allows the leading 00 in the program to be parsed as a pointless assignment statement.

When the program is doubled, however, the 0s are no longer leading a numeric literal—they are a continuation of the literal 1 at the end of the program, forming 100.

# Labyrinth, 8 5 bytes

-3 bytes thanks to @MartinEnder

Single version

^)!@



Try it online!

Double version

^)!@
^)!@



Try it online!

• Nice work, this is a really neat solution! :) I got curious and set a brute force solution on this problem and it found a whole bunch of 5-byte solutions (all of which print 1 and 2, some of them with leading zeros). Feel free to add any of them to your answer pastebin.com/RRFxZEuN (I don't care about posting them myself, since you clearly put more effort into your 8-byte solution than I did into just brute forcing the optimal ones.) – Martin Ender Feb 18 '18 at 16:55

# bash builtins only - 21 bytes

The X file:

trap "echo $[++i]" 0;  EXIT –> 0 $((...)) -> $[...] ;-) # bash builtins only - 26 bytes Straight forward while using only bash builtins. IOW: No external helpers. The X file: trap "echo$((++i))" exit;


(No final newline.)

Proof of the pudding:

$bash <(cat X) 1$ bash <(cat X X)
2
$bash <(cat X X X) 3  Concat with or without newline inbetween: $ cat X X ; echo # added echo compensates missing \n only
trap "echo $((++i))" exit;trap "echo$((++i))" exit;
$bash <(cat X X) 2$ cat X <(echo) X ; echo
trap "echo $((++i))" exit; trap "echo$((++i))" exit;
$bash <(cat X <(echo) X) 2  # Rust, 81 bytes mod x{pub const Y:i8=1;}use x::*;fn main(){print!("{}",Y)}/* const Y:i8=2;// *///  Doubled: mod x{pub const Y:i8=1;}use x::*;fn main(){print!("{}",Y)}/* const Y:i8=2;// *///mod x{pub const Y:i8=1;}use x::*;fn main(){print!("{}",Y)}/* const Y:i8=2;// *///  Rust pretty much doesn't allow duplicate items in a source code. For instance, following code causes an error due to an item defined multiple times. const Y: i32 = 2; const Y: i32 = 2;  There are three exceptions to this rule. • Macros - which are pretty much useless, as macros don't follow the usual visibility rules - code cannot refer to a macro later in the code. • Wildcard imports - if there is a non-wildcard import, it has precedence while resolving item references. This is to help avoid incompatibilities caused by other crates (including std itself) adding more public items. • Overriding a builtin item or item from prelude - see bonus below, this way turned out to be longer, but also has more potential for improvements. I decided to go with duplicating an item by using a glob import. This necessiated making a module. mod x { ... }  That had a public item in it. Not public items aren't accessible outside of module that defined them. i8 type was chosen because it's the shortest integer type -- a type needs to be declared for const items, this cannot be skipped. A string literal wasn't used as &str is 2 bytes longer, and also quotes would be necessary, not saving bytes even with removal of "{}", from main function. Adding 6 bytes is not worth it for removing 5 bytes. pub const Y: i8 = 1;  Later I glob import this constant. Note that the constant can be overridden by a different non-wildcard declaration. use x::*;  And a function prints whatever value Y holds. Note that Y can be overridden by a non-wildcard declaration. This is important when doubling source code. print! ends with an exclamation mark as it is a macro. As the first parameter is a formatting pattern, I cannot use an integer directly, instead I have to specify "{}", formatting pattern. Missing semicolon at the end of block means that this block returns a value. This is fine, as main returns () (implicit, due to not specifying another return type), and print! macro returns () (as in, it doesn't have an useful return value). fn main() { print!("{}", Y) }  Later, I want there to be a second declaration of Y, but I don't want it come into play for the first pass, so I comment it out. There is a newline, so that a line comment that will be declared later won't skip over a constant declaration. There is a space after // as there is nested comments feature, otherwise Rust would see /* inside block comment and start a nested comment. /* const Y:i8=2;// */  At end, I put //, so that first line of code of code is skipped when the code is doubled. It involves items that cannot be defined multiple times. //  The execution may conntinue from second line. If it does, value of Y used by main function will be different.  const Y: i8 = 2;  A line comment is included so that closing block comment that was needed for first pass won't cause issues. // *///  And that's it, a program that detect it being duplicated in Rust done in 81 characters. Thank you for reading this explanation. # Bonus (alternative way for possible improvements, 93 92 bytes) Instead of using glob imports, it's possible to override one builtin items from either a builtin type or something imported from prelude. fn main(){println!("{}",i8::max_value())}/* enum i8{}impl i8{fn max_value()->u8{254}}// *///  However, this solution is currently longer than the solution above. • Same length (81 bytes), but I thought I'd share a slightly different version of your answer that uses #[test] instead: TIO. – TehPers Aug 6 '20 at 22:27 • @TehPers I like the idea of using #[test], clever :). – Konrad Borowski Aug 7 '20 at 10:46 # Ruby, 10 bytes +1;a||=p 1  Try it online! Try it online!Try it online! Explanation: • Single version (+1;a||=p 1): • +1 is ignored • a is assigned to 1 (printing 1 in the process) because a was previously undefined • Double version (+1;a||=p 1+1;a||=p 1) • +1 is ignored • a is set to 1+1 (2) (printing 2 in the process) because a was undefined • The next part is not executed because a is already defined # CJam, 4 bytes 1]:+  Try it online! Explanation: 1]:+ 1 push 1 to stack ]:+ sum stack  # CJam, 1 byte )  Try it online! I'd say this uses 2 bytes since there is a 0 in the header. I don't know if this is a valid loophole or forbidden. • The second one isn't valid since it doesn't work without the 0 – Jo King Jan 19 '19 at 4:16 # K (ngn/k), 3 bytes +/1  Try it online! +/1 - sum 1. returns 1 +/1+/1 - rightmost +/1 evaluates to 1 (as above), giving +/1 1, i.e. sum the vector 1 1. returns 2 # GAS x64 Assembly (Linux, GCC 10.1): 143 107 104 100 bytes Assembled with -no-pie -nostdlib. ## Original code lea a,%rsi lea 2,%dx lea 1,%di lea 1,%ax syscall .ifndef b ja b .endif a=. .ascii " 1\b2" a=a+2 b=.;  ## Annotated Single Single one segfaults, printing 1 to the terminal with a leading space. (Rules say this is OK.) // Print 2 characters from a // Use lea so we don't need$.
// We are optimizing for assembly, not machine code
lea a,%rsi
lea 2,%dx
lea 1,%di
lea 1,%ax
syscall

// Since b hasn't been defined yet, this gets left in, jumping to b
// (Pseudo-op is needed when we double)
.ifndef b
// Since gcc clears all flags at the start
ja b
.endif

// You can define re-writable labels like this too!
a=.
.asciz " 1\b2"

// Increase a by 2 (needed in double version)
a=a+2

// Attempt to jump here, but crash because there's no executable code
// Also, intentional semicolon to separate double version
b=.;

// Let crash


Gives the following:

 1[1]    74584 segmentation fault (core dumped)  ./a.out


The first 1 is the program output. Since Segfault stuff isn't program output, we're good.

## Annotated Double (fluff removed)

Takes advantage of the backspace character, overwriting the 1 with a 2. (Also segfaults)

// Print 2 characters
lea a,%rsi
lea 2,%dx
lea 1,%di
lea 1,%ax
syscall

ja b

// Every reference to a prior to this line points here
a=.
.ascii " 1\b2"
// Now point a to \b for next usage
a=a+2

// Now print the last two characters from new a
b=.
lea a,%rsi
lea 2,%dx
lea 1,%di
lea 1,%ax
syscall

// Crash

 2[1]    391605 segmentation fault (core dumped)  ./a.out

• Before trying to improve this: Don't get confused between ASCII '1' and byte 0x1. This is very easy to do when you're dealing with low-level. ASCII '1' is 0x31 or 49, which none of these instructions or operands will assemble to in bytecode. – Calculuswhiz Jun 7 '20 at 2:30

# Flurry, 6 bytes

([])[]


### Verification

$echo -n "([])[]" | wc -c 6$ ./flurry -nin -c "([])[]"
1
\$ ./flurry -nin -c "([])[]([])[]"
2


Found by accident (kind of). Single copy returns 1, two copies returns 2.

(...) pushes its content to the stack, and [] evaluates to the stack height in Church numeral. Juxtaposition is function application (which is reversed exponentiation for Church numerals), so the entire code evaluates like the following:

Single copy
([])    Evaluate to stack height (0), and push 0 to the stack
[]      Evaluate to stack height (1)
Function application gives 1 ** 0 = 1

Two copies
([])[]  Evaluate as above; evaluates to 1 and pushes a 0
([])    Evaluate to stack height (1), and push 1 to the stack
Function application gives 1 ** 1 = 1
[]      Evaluate to stack height (2)
Function application gives 2 ** 1 = 2


Honorable mention goes to the literal 2:

# Flurry, 10 bytes

{<({}){}>}


Returns 2 as-is, and returns 4 (= 2**2) when doubled.

I call it a "literal" because it is a single pure {...} node (so it can be placed in larger programs without modification), and any number constant can be constructed using the same pattern.

{       Start a lambda; implicitly pushes its argument before running
<      Start a function composition group
({})  Pop the argument {} and push again (...)
{}    Pop the argument again
>      End composition group
}       End lambda

Evaluates to the following lambda function
\f. f ∘ f
= \f. \x. f (f x)
= 2


To create a higher number n, we can place n-1 copies of ({}) before {}, which then evaluates to \f. f ∘ f ∘ ... ∘ f (n copies), which is precisely n in Church numeral. For example, 3 can be written as {<({})({}){}>}, which is similar to what I previously used.