Anybody can make the output of a program bigger by adding characters, so let's do the exact opposite.

Write a full program, an inner function or a snippet for a REPL environment in a language of your choice that satisfies the following criteria:

  1. Your code must be at least 1 character long.

  2. Running the original code produces x characters of output to STDOUT (or closest alternative), where 0 ≤ x < +∞.

  3. Removing any arbitrary single character from the original code results again in valid code, which produces at least x + 1 characters of output to STDOUT.

  4. Neither the original code nor the modifications may produce any error output, be to STDOUT, STDERR, syslog or elsewhere. The only exceptions to this rule are compiler warnings.

    Your program may not require any flags or settings to suppress the error output.

    Your program may not contain any fatal errors, even if they don't produce any output.

  5. Both the original code and the modifications must be deterministic and finish eventually (no infinite loops).

  6. Neither the original code nor the modifications may require input of any kind.

  7. Functions or snippets may not maintain any state between executions.

Considering that this task is trivial is some languages and downright impossible in others, this is a .

When voting, please take the "relative shortness" of the code into account, i.e., a shorter answer should be considered more creative than a longer answer in the same language.

  • 2
    \$\begingroup\$ While the 1 byte solution is impressive, it would be more impressive to see who can come up with the highest ratio of x:x+n. i.e. the length of normal output compared to the average length of output when any one character is removed. Adds an extra challenge to this question in my opinion. \$\endgroup\$
    – Trent
    Commented Jun 24, 2015 at 2:49
  • \$\begingroup\$ @FizzBuzz Easy: 111111111111111111^111111111111111111 (if you meant the lowest ratio). \$\endgroup\$
    – jimmy23013
    Commented Jun 24, 2015 at 12:30
  • 2
    \$\begingroup\$ Aw, just noticed 'no infinite loops.' I was working on creating a ><> program that would create output faster if an one character was removed, such that after a constant k instructions, the output of each program is strictly greater than the output of the original from then on (because the other programs would loop faster or output more each loop). It was looking pretty interesting. Maybe I'll see if I can finish it anyway, and make another challenge. \$\endgroup\$
    – mbomb007
    Commented Jun 24, 2015 at 17:28
  • \$\begingroup\$ An interesting scoring metric for this challenge could be "most unique characters, ties go to shortest length". We would then try to get all the characters in a string literal though. \$\endgroup\$
    – lirtosiast
    Commented Jul 1, 2015 at 23:11
  • \$\begingroup\$ What is meant by an inner function? \$\endgroup\$
    – dfeuer
    Commented Apr 1, 2019 at 4:16

27 Answers 27


Any REPL with caret XOR operation, 5 bytes


11^11 is of course 0. The only other possibilities are 1^11 or 11^1 which are 10, or 1111 which produces itself.

  • 7
    \$\begingroup\$ Well played, feersum. Well played. \$\endgroup\$
    – Alex A.
    Commented Jun 23, 2015 at 19:48
  • 14
    \$\begingroup\$ Minus would also do the trick. \$\endgroup\$ Commented Jun 23, 2015 at 19:49
  • 11
    \$\begingroup\$ Similarly, 99|99 \$\endgroup\$
    – Sp3000
    Commented Jun 24, 2015 at 3:30
  • \$\begingroup\$ @Challenger5 -10 is longer than 0. \$\endgroup\$ Commented Nov 8, 2017 at 8:20
  • \$\begingroup\$ @MartinEnder Oh, I see. For some reason I thought it had to be a larger number. \$\endgroup\$ Commented Nov 8, 2017 at 8:25



When the last line of a program is an expression, the calculator will display that expression. Otherwise, the calculator displays Done when the program finishes. The expression here is the empty string, but it could also work with any one-digit number.

2 bytes:


Same as the above but with a 2-byte token.

3 bytes:


Prints 1 due to implied multiplication. Can be extended indefinitely by adding pairs of ⁻¹'s. The below also work.


Longer solutions:

cos(208341   //numerator of a convergent to pi; prints "-1"

There are probably also multi-line solutions but I can't find any.

  • \$\begingroup\$ I'm not familar with TI BASIC. Are you counting the sqrt and parenthesis as a single character? \$\endgroup\$ Commented Jun 23, 2015 at 20:03
  • 6
    \$\begingroup\$ Yes, the sqrt and parenthesis are together a single token, stored as one byte in the calculator's memory and entered with one keypress. \$\endgroup\$
    – lirtosiast
    Commented Jun 23, 2015 at 20:04
  • 8
    \$\begingroup\$ finally a way to stop that annoying Done message! \$\endgroup\$ Commented Jun 23, 2015 at 20:33
  • 1
    \$\begingroup\$ There is no Done token; the calculator displays Done when finished executing any program without an expression on the last line (including the empty program). \$\endgroup\$
    – lirtosiast
    Commented Jun 28, 2015 at 17:27

CJam, JavaScript, Python, etc, 18 bytes


The outputs in CJam are:

8.8888888888888888 -> 8.88888888888889
8.888888888888888  -> 8.888888888888888
88888888888888888  -> 88888888888888888
.8888888888888888  -> 0.8888888888888888

JavaScript and Python work in similar ways. It isn't competitive in JavaScript and Python, but it's not easy to find a shorter one in CJam.

  • 16
    \$\begingroup\$ Nice floating-point abuse! \$\endgroup\$
    – nderscore
    Commented Jun 25, 2015 at 1:10

Octave, 5 bytes


(x : y) gives the array of numbers between x and y in increments of 1, so between 10 and 10 the only element is 10:

> 10:10
ans = 10

When the second argument is less than the first, octave prints the empty matrix and its dimensions:

> 10:1
ans = [](1x0)

> 10:0
ans = [](1x0)

When a character is removed from the first number, there are more elements in the array:

> 1:10
ans = 1 2 3 4 5 6 7 8 9 10

> 0:10
ans = 0 1 2 3 4 5 6 7 8 9 10

When the colon is removed, the number returns itself:

> 1010
ans = 1010
  • 1
    \$\begingroup\$ also valid in R \$\endgroup\$
    – mnel
    Commented Mar 8, 2016 at 10:17

Microscript, 1 byte


This produces no ouput, as h suppresses the language's implicit printing. Removing the sole character produces a program whose output is 0\n.

I'll try to come up with a better answer later.


This also works in Microscript II, with the exception that, instead of yielding 0\n, the empty program yields null.


Pyth, 3 bytes


G is preinitialized with the lowercase letters in the alphabet. c is the split-function.

cGG splits the alphabet by occurrences of the alphabet, which ends in ['', ''] (8 bytes).

When the second parameter is missing, c splits the string by whitespaces, tabs or newlines. Since none of them appear in G, the output for cG is ['abcdefghijklmnopqrstuvwxyz'] (30 bytes).

And GG simply prints twice the alphabet on two seperate lines: abcdefghijklmnopqrstuvwxyz\nabcdefghijklmnopqrstuvwxyz (53 bytes).

Try it online: Demonstration


Python REPL, 6 bytes

Not the shortest, but here's another floating point abuse answer:

>>> 1e308
>>> 11308
>>> 11e08
>>> 11e38
>>> 11e30


>>> 11e308

JavaScript (and a lot more), 5byte

44/44 or

44/44 -> 1
44/4  -> 11
4444  -> 4444
4/44  -> 0.09090909090909091

CJam, 5


Try it online

''''=   compares two apostrophes and prints 1
'''=    prints '=
''''    prints ''

Lenguage, 5 bytes


The length of the program is 5 which corresponds to the brainf*** program , reading an end of input character and terminating without output.

Removing any char results in the code 0000 which has a length of 4 corresponding to the brainf*** program . printing out one character (codepoint 0) and terminating.

The Unary equivalent would be 0000000000000 (13 zeros) because you have to prepend a leading 1 to the binary length of the code so 101 becomes 1101.


PHP, 6 bytes

I have been watching this group for a couple of weeks and am amazed of your programming techniques. Now I had to sign in, there is something I can do, sorry :-) However, this might be my last post here...


(note the space after second p)

This outputs empty string. Removing any character outputs the text without the character. Note it can produce HTML errors (content not rendered by browsers for eg. <?ph).

I also tried with the echo tag. ie. eg.:

<?= __LINE__;;

This one outputs 1. If = is omitted, <? __LINE__;; is the output. However, removing any of the magic constant character will result in E_NOTICE: Notice: Use of undefined constant LNE - assumed 'LNE' in...

If notices are not considered errors (point 4 of rules), this also applies :-)

  • \$\begingroup\$ Oh, that's clever. I guess a linefeed would work as well. If the task was to produce HTML, this would be invalid. However, PHP can be run from the command line, just like any other programming language, where the output is simply printed to the screen. \$\endgroup\$
    – Dennis
    Commented Jun 25, 2015 at 20:43
  • \$\begingroup\$ @Dennis PHP outputs anything. You can always use CTRL-U in your browser to see the output. HTML might be invalid, but in fact the program is not (there is no <HTML> tag etc.) \$\endgroup\$
    – Voitcus
    Commented Jun 25, 2015 at 20:45
  • 1
    \$\begingroup\$ My point is that there's no need to involve a browser at all. Just execute php test.php. The second code is invalid by the way. The question does not forbid errors but error output, meaning errors, warning, notices, etc. \$\endgroup\$
    – Dennis
    Commented Jun 25, 2015 at 20:48
  • 2
    \$\begingroup\$ #! in a script file also works. \$\endgroup\$
    – jimmy23013
    Commented Jun 26, 2015 at 1:46

Python, 10 8 bytes


Works in Python and friends. Thanks to Jakube for showing how to make it 2 bytes smaller.

From IDLE:

>>> 256**.25
>>> 26**.25
>>> 56**.25
>>> 25**.25
>>> 256*.25
>>> 256*.25
>>> 256**25
>>> 256**.5
>>> 256**.2

originally I had this (10 bytes):


From IDLE:

>>> 14641**.25
>>> 4641**.25
>>> 1641**.25
>>> 1441**.25
>>> 1461**.25
>>> 1464**.25
>>> 14641*.25
>>> 14641*.25
>>> 14641**25
>>> 14641**.5
>>> 14641**.2

and on the same note:


works identically due to nice rounding by Python, in 17 bytes.

>>> 121**.25*121**.25
>>> 21**.25*121**.25
>>> 11**.25*121**.25
>>> 12**.25*121**.25
>>> 121*.25*121**.25
>>> 121*.25*121**.25
>>> 121**25*121**.25
>>> 121**.5*121**.25
>>> 121**.2*121**.25
>>> 121**.25121**.25
>>> 121**.25*21**.25
>>> 121**.25*11**.25
>>> 121**.25*12**.25
>>> 121**.25*121*.25
>>> 121**.25*121*.25
>>> 121**.25*121**25
>>> 121**.25*121**.5
>>> 121**.25*121**.2
  • \$\begingroup\$ @Akiino I do not understand the edit you made. The line you removed was one of the required possibilities and no different then any of the ones below it. Could you explain why you removed it? I rolled it back, but can concede to undo the action with adequate reasoning. \$\endgroup\$
    – rp.beltran
    Commented Jan 7, 2016 at 19:05
  • \$\begingroup\$ My inner perfectionist just couldn't sleep well knowing that the line (the one that i removed) is duplicated for no reason. There are lines 56..., 26... and then 56... again, but there is only one way to get 56, so it should be included only once, isn't it? \$\endgroup\$
    – user38962
    Commented Jan 9, 2016 at 12:01
  • \$\begingroup\$ Oh, I didn't see that it was on there twice. My bad, good catch. \$\endgroup\$
    – rp.beltran
    Commented Jan 9, 2016 at 18:51
  • \$\begingroup\$ I rolled back my rollback. \$\endgroup\$
    – rp.beltran
    Commented Jan 9, 2016 at 18:52

SWI-Prolog interpreter


Note: You cannot remove the final .. Prolog interpreters will always look for a final period to run your query, so if we stick strictly to the rules of this contest and allow ourselves to remove the period it won't run, it will jump a line and wait for additional commands until one is ended by a period.

The original query __A=__A. outputs true..

The query _A=__A. outputs _A = '$VAR'('__A'). Similar modifications (i.e. removing one _ or one of the two A) will result in similar outputs.

Finally, the query __A__A. outputs in SWI-Prolog:

% ... 1,000,000 ............ 10,000,000 years later
%       >> 42 << (last release gives the question)
  • 12
    \$\begingroup\$ @Jakube I don't see how having a mandatory final period is a lot different than having to input the enter key to run a snippet in another language. If you remove the linefeed it won't run either. \$\endgroup\$
    – Fatalize
    Commented Jun 24, 2015 at 9:34
  • \$\begingroup\$ It is more equivalent to a semicolon in some languages, and that does count as a character. \$\endgroup\$
    – tomsmeding
    Commented Jun 29, 2015 at 16:26

Sed, 1 byte


As sed requires an input stream, I'll propose a convention that the program itself should be supplied as input.

$ sed -e 'd' <<<'d' | wc -c
$ sed -e '' <<<'d' | wc -c

An alternative program is x, but that only changes from 1 to 2 bytes of output when deleted.


K, 3 bytes


Outputs 0 in the REPL. Removing the first 2 outputs 0 1, removing the exclamation results in 22, and removing the last 2 results in a string that varies between K implementations but is always at least 2 characters (in oK, it's (2!); according to @Dennis, Kona outputs 2!).

  • \$\begingroup\$ @Sp3000 Removing the * just prints 2. Removing the 2 prints (*!) (an incomplete function) in oK; I don't know about other interpreters (e.g. Kona, k2, etc.), although I believe Kona would print *[!;] or something similar. I went with removing the star because it seemed the safest. \$\endgroup\$ Commented Jun 24, 2015 at 1:23
  • \$\begingroup\$ You can't choose, It must work removing any character \$\endgroup\$
    – edc65
    Commented Jun 24, 2015 at 1:24
  • \$\begingroup\$ @edc65 Fixed at the expense of not a single byte. \$\endgroup\$ Commented Jun 24, 2015 at 2:01
  • 1
    \$\begingroup\$ @Dennis Updated. \$\endgroup\$ Commented Jun 24, 2015 at 14:22

MATLAB, 9 7 bytes

It's 2 bytes longer than the other MATLAB/Octave answer, but I like it nonetheless, as it's a bit more complex.

Matlab's ' operator is the complex conjugated transpose. Using this on a scalar imaginary number, you get i' = -i. As imaginary numbers can be written simply as 2i one can do:

ans =

Removing any one of the characters will result in one of the below:

ans =
   0.0000 - 1.0000i
   2.0000 - 2.0000i
   0.0000 + 4.0000i
   0.0000 + 4.0000i
   0.0000 + 1.0000i
   2.0000 + 2.0000i
   0.0000 + 4.0000i

GolfScript, 2 bytes

This answer is non-competing, but since it is the piece of code that inspired this challenge, I wanted to share it anyway.


By default, all GolfScript programs print the entire stack, followed by a linefeed, by executing puts on the entire stack. The function puts itself is implemented as {print n print} in the interpreter, where print is an actual built-in and n is a variable that holds the string "\n" by default.

Now, a GolfScript program always pushes the input from STDIN on the stack. In this case, since there isn't any input, an empty string is pushed. The variable assignment :n saves that empty string in n, suppressing the implicit linefeed and making the output completely empty.

By eliminating n, you're left with the incomplete variable assignment : (you'd think that's a syntax error, but nope), so the implicit linefeed is printed as usual.

By eliminating :, you're left with n, which pushes a linefeed on the stack, so the program prints two linefeeds.


J, 5 bytes


Magnitude of the complex number 5 + 12i in REPL.

   |5j12 NB. original, magnitude of the complex number `5 + 12i`
   5j12  NB. the complex number `5 + 12i`
   |j12  NB. magnitude of the undefined function j12
| j12
   |512  NB. magnitude of 512
   |5j2  NB. magnitude of 5 + 2i
   |5j1  NB. magnitude of 5 + 1i


J, 9 bytes


Based on floating point precision, reciprocal and matrix inverse.

   %0.333333 NB. original, reciprocal of 0.333333
   0.333333  NB. 0.333333
   %.333333  NB. matrix inverse of 333333
   %0333333  NB. reciprocal of 333333
   %0.33333  NB. reciprocal of 0.33333

Try it online here.


APL, J and possibly other variants, 3 bytes


It outputs 1 in APL. -1 outputs ¯1, and -- outputs the following in TryAPL:

- -

Mathematica, 3 bytes


4!0  ->  0    the factorial of 4, times 0
4!   ->  24   the factorial of 4
40   ->  40
!0   ->  !0   the logical not of 0, but 0 is not a boolean value

Dyalog APL, 2 bytes

⍴0 returns an empty string (length 0)

returns (length 1)

0 returns 0 (length 1)


Swift (and a lot more), 8 bytes


output (4 chars):


When removing the nth character the output is:

n -> out
0 -> false
1 -> false
2 -> false
3 -> false
4 -> false
5 -> 10077
6 -> false
7 -> false

There are 78 possible solutions like this in the format of a^b<c.

I think the goal of this challenge should be as many bytes as possible, because the more bytes, the more possible bytes to remove and therefore more difficult.

  • \$\begingroup\$ I thought about that, but it would have been to easy for stack-based languages. If this was a code bowling challenge, aditsu would have an infinte score. His code can be repeated over and over again; each copy will do exactly the same. \$\endgroup\$
    – Dennis
    Commented Jun 29, 2015 at 23:41
  • \$\begingroup\$ @Dennis Oh I see, yeah makes sense, but I think bytes are maybe not a very good measure for this task \$\endgroup\$
    – Kametrixom
    Commented Jun 30, 2015 at 1:13
  • \$\begingroup\$ I agree. That's why it's a popularity contest. Most upvoted answer wins. \$\endgroup\$
    – Dennis
    Commented Jun 30, 2015 at 2:05

MathGolf, 2 bytes


Try it online!


♂   Push 10
 (  Decrement TOS by 1

Why does this work?

The regular output is 9. If the ( is removed, the output is 10. If the is removed, the program implicitly pops a 0 from the stack to feed the ( operator, which outputs -1.


05AB1E (legacy), 1 byte

Any single byte in 05AB1E (legacy) would work, except for [ (infinite loop).

See here all possible outputs for all possible single-byte 05AB1E programs.

Removing that single byte so an empty program remains will output the content of info.txt to STDOUT instead by default.

Try it online.

05AB1E, 1 byte


Try it online.

Unfortunately an empty program in the new version of 05AB1E only outputs a 1-byte newline by default (Try it online), so almost none of the 1-byte characters are possible since they'll have to output nothing. The only possible program that outputs nothing (so also not the implicit newline) is ? as far as I know.


Clojure, 11 bytes

(defn x[]1)

At first I thought to just post a single character answer in the REPL like the other languages, e.g.

user=> 1

But the problem is that if you remove that character, the REPL doesn't do anything upon the enter keypress. So instead it had to be wrapped with a function as permitted by the question's rules. When you call this function, it returns 1. If you remove the only character in the function,

(defn x[])

the function returns nil which prints an additional two bytes.

user=> (defn x[]1)
user=> (x)
user=> (defn y[])
user=> (y)
  • 1
    \$\begingroup\$ To clarify: The contest requires an inner function, which would be 1 in this case (1 byte). \$\endgroup\$
    – Dennis
    Commented Jun 24, 2015 at 16:24

Japt, 2 bytes

Try it online!

A is pre-initialized to 10, É subtracts 1, and the result is 1 byte: 9.

Removing É results in the program A, which outputs A's value, 10, so the result is 2 bytes.

Similarly, removing A results in just É which is interpreted as -1 and output as -1, so the result is 2 bytes.


Runic Enchantments, 6 (modifiable) bytes


Try it online!

Runic does not have a REPL environment and writing a full program to satisfy the constraints is not readily feasible (leading to either invalid programs or no output). So the portion of the code 11-{{B is acting as an inner function and only this portion can be modified. The B instruction is close enough to a function pointer and return statement that this classification should be acceptable (as it jumps the IP to a position in the code as well as pushing a return location to the stack which may be accessed by a subsequent B or discarded).

  • Standard output: 0
  • Removing either of the 1s: 05
  • Removing the -: 11
  • Removing either {: Error051
  • Removing the B: 120

The final \ on the end of the first line provides an external boundary around the inner function in the event that the return instruction is removed so that the IP doesn't go meandering all over everywhere willy nilly (and print no output).

Note that Error051 is just an arbitrary string, I could put anything I wanted into that portion of the code and "Error" was an amusing result for having code that feks up the return coordinates and the IP teleports to an arbitrary location.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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