Related: I double the source, you double the output!

When Steve Jobs launched the iPhone 3G, the slogan said

Twice as fast, half the price

I changed the word fast to long to better represent this challenge.


Write a program that outputs a non-zero, even integer. If the source code is doubled, the value of the output must be cut off by half.

To double the source in a Unix shell (with Core Utilites):

cat source.txt source.txt > doubled-source.txt

Rules & Requirements

Now the requirement has changed and the task has been even more challenging!

  • You must build a full program.
  • The initial source is no longer required to be at least 1 byte long. An empty program qualifies as long as the output is correct.
  • Both the integers must be in base 10 (outputting them in any other base or with scientific notation is forbidden), and must not be zero. The integer is no longer required to be positive, so if you like a negative number, it's OK.
  • Your program must not take input (or have an unused, empty input) and must not throw any error (compiler warnings are not considered errors). Exit code must be zero.
  • Outputting the integers with trailing / leading spaces / newlines is allowed, as long as only one integer is output.
  • You can't assume a newline between copies of your source. If you need one, clarify it. See the Unix shell command above.
  • Standard loopholes are forbidden.

Because this is a , the shortest (original, undoubled) code in each language wins!


Please give description / explanation to your code if possible.

  • \$\begingroup\$ Must the old and new program be in the same language? \$\endgroup\$
    – tsh
    Commented Aug 29, 2017 at 4:03
  • \$\begingroup\$ @tsh Definitely \$\endgroup\$
    – iBug
    Commented Aug 29, 2017 at 4:10
  • 2
    \$\begingroup\$ By the way, zero byte answers to this question can't exist. \$\endgroup\$
    – Joshua
    Commented Aug 29, 2017 at 4:20
  • 1
    \$\begingroup\$ @WheatWizard This is exactly the opposite. \$\endgroup\$
    – Arthur
    Commented Aug 29, 2017 at 6:42
  • \$\begingroup\$ @Arthur That is somewhat true but also misleading. The only difference between this question and that is the operation involved. I consider this a rather minor difference that doesn't add anything not already present in the original. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 29, 2017 at 6:45

7 Answers 7


Brain-Flak, 12 bytes


Outputs 2. Try it online!

The doubled program outputs 1. Try it online!


This code pushes 2 + stack height - top of stack. Initially, this is 2 + 0 - (implicit) 0 = 2. When this code is run again, it pops the existing 2 and pushes 2 + 1 - 2 = 1.

  • \$\begingroup\$ This is in fact a provably optimal solution. I don't have the space for the complete proof in this comment but it's not very complex, feel free to ping me in chat for a complete proof. \$\endgroup\$
    – Wheat Wizard
    Commented Aug 29, 2017 at 6:56

Python 2, 35 34 bytes

Uses a concept similar to that of Wheat Wizard in the double challenge with an improvement I found to his original code. Here I use the fact that the length of the file is 34 bytes long. Meaning it is equal to 4 modulo 6. (34%6 = 4). The double source code would have a length of 68. And 68%6 = 2, which is exactly what we want.

print open(__file__,"a").tell()%6#

Try it online!

Double source code


This opens the source code file in append mode


We then find the current position in the file, this will be at the end of the file due to opening in append mode


We print this length modulo 6

print open(__file__,"a").tell()%6

And add a comment, so that doubling the source code does not execute more code

print open(__file__,"a").tell()%6#

Jelly, 2 bytes


Outputs 2, Try it online!



Outputs 1, Try it online!


The default input to a monadic chain is zero...

¬‘   - Main link: no arguments
¬    - logical not -- not the implicit input of 0 to yield 1
 ‘   - increment   -- increment 1 to yield 2
     - implicit print if this is the end of the program, otherwise...
  ¬‘ - continues the monadic chain:
  ¬  - logical not -- not the 2 to yield 0
   ‘ - increment   -- increment 0 to yield 1
     - implicit print if this is the end of the program

The two byters:

Ị‘ - insignificant (abs(z)<=1); increment
Ṇ‘ - non-vectorising logical not; increment

would work too.


Ly, 7 bytes


Try it online!

Simple port of the Brain-Flak answer.


05AB1E, 3 bytes

Outputs 4


Try it online!

Doubled Source

Outputs 2


Try it online!


6      # push 6
 r     # reverse the stack (does nothing)
  Í    # subtract 2

With the doubled source we continue with

6      # push 6
 r     # reverse the stack (puts 4 on top)
  Í    # subtract 2
  • \$\begingroup\$ Does the r in the singlet form of your answer put 4 on top the top of the stack? \$\endgroup\$ Commented Sep 10, 2017 at 19:25
  • \$\begingroup\$ @TaylorScott: In the single form we only have a 6 on the stack so r does nothing. \$\endgroup\$
    – Emigna
    Commented Sep 11, 2017 at 5:12

Jelly, 7 bytes


Try it online!

Outputs 2.

Duplicated Source:


Try it online!

Outputs 1.


sh, 50 bytes

expr 200 / `wc -c $0 | cut -c 1-3`

Not the answer you're looking for? Browse other questions tagged or ask your own question.