15
\$\begingroup\$

Your task is to write a program \$p\$ which outputs a string \$s\$ with the same length as \$p\$, where \$s \neq p\$.

If I remove the \$n\$th byte from your program to get program \$q\$, then either \$q\$ outputs \$s\$ with the \$n\$th byte removed, or it does something else.

Your score is the number of ways a single byte being removed from \$p\$ results in a program that does "something else" or that has become a quine, with a lower score being the goal. Ties will be broken by code golf.

Note that the effective smallest byte count for an answer with score 0 is 2 bytes (not accounting for fractional byte systems).

\$\endgroup\$
8
  • 1
    \$\begingroup\$ If my program has a non-integer number of bytes, what length string should I output? Should I round-up, round-down, or just write another program? \$\endgroup\$ Oct 1 at 15:40
  • 1
    \$\begingroup\$ @DominicvanEssen I would say, if the score is fractional, you should output a fractional number of bytes, I don't think there's any ambiguity there. However the issue for me is that removing bytes from a fractional program doesn't make sense, and I don't have a way to resolve it. I think for now answers in fractional byte languages must have an integer number of bytes. \$\endgroup\$
    – Wheat Wizard
    Oct 2 at 1:01
  • 1
    \$\begingroup\$ Does not being a valid progam count as "something else"? \$\endgroup\$
    – G. Sliepen
    Oct 2 at 9:23
  • \$\begingroup\$ @G.Sliepen Yes. \$\endgroup\$
    – Wheat Wizard
    Oct 2 at 11:53
  • 1
    \$\begingroup\$ @PeterCordes I think it should be possible starting from a quine (you can even have those in C that are very short), and then modifying it such that adding one specific extra character will get it printing not quite the source. That last part is quite tricky though... \$\endgroup\$
    – G. Sliepen
    Oct 3 at 8:24

5 Answers 5

17
\$\begingroup\$

brainfuck, 2 bytes, score 0

..

Try it online!

Outputs two null bytes.

Removing either . leaves ., which outputs one null byte. (Try it online!)

\$\endgroup\$
8
\$\begingroup\$

Charcoal, 4 bytes, score 0

¹--¹

Try it online! Explanation: ¹ on its own outputs a -, so the whole program outputs 4 -s. (I could have used any two ASCII characters in the middle; I just chose - to be confusing.) Removing any character results in a program that outputs 3 -s. I need both ¹s to prevent the program from becoming a (trivial) quine, and I need two -s to prevent the ¹s from being interpreted as 11 when they are adjacent.

\$\endgroup\$
1
  • \$\begingroup\$ I thought those were strange looking quotes for a second... \$\endgroup\$
    – Jo King
    Oct 1 at 15:22
5
\$\begingroup\$

R REPL*, 125 90 bytes, score 0

*(or any other R environment in which errors do not halt execution of subsequent commands: entering the program into the R interactive console works fine; alternatively (and as simulated in the ATO link) we can use the command-line option -e 'options(error=function(){})', which would define the language as "R -e 'options(error=function(){})'".

x=1;if(x)cat(strrep(x,9*(2)*5-(nchar(readLines(c=stdin(),n=1))<9*(2))))
cat(strrep(1,89))#

Attempt This Online!

The strategy here is to write a 2-line program. If the first line runs Ok, it uses the second line as input (and, as a side-effect, prevents the second line from running), and checks that it contains the expected number of characters: if it does, print string s (90 1s); if it doesn't, print string s without one character (all the characters are the same, so this is equivalent to removing the nth character for any n).
The first line is written to error (and so do nothing) if any character is removed. In this case, the second line won't be used as input, and it will run: it always prints string s without 1 character.

The length of the entire program is expressed as 9*(2)*5 (so removing any character will error). For a similar reason, the second line is adjusted to be 18 characters long, so we can check whether its length is less than 9*(2).


R, 8 bytes, score 8

cat(8^8)

Attempt This Online!

In principle, we could try to wrap the R+REPL program above into a tryCatch() expression to force it to run in base R, but this would already inflate the score to at least 10, and this trivial approach is both shorter and scores better (even though it's rather boring).

\$\endgroup\$
2
\$\begingroup\$

Vyxal, 2 bytes, score 0

₴₴

Try it Online!

Prints 2 0s. Removing either print without newline prints only 1 0.

\$\endgroup\$
0
1
\$\begingroup\$

MathGolf, 2 bytes, score: 0

⌂⌂

Outputs **:
Try it online.

If either is removed, it'll only output a single *:
Try it online.

Explanation:

⌂   # Push "*" to the stack
 ⌂  # Push "*" to the stack again
    # (after which the entire stack is joined together and output implicitly as result)
\$\endgroup\$

Your Answer

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

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