Stax, 11 bytes (Score of 4)
'''cc'~~'dd
Run and debug online!
It is my honor to have the first (chronologically) answer to this challenge with a score higher than or equal to 4. Maybe the score can be even higher though.
In Stax, a string literal that is composed of a single character is written with '
, so '', 'c, 'd, '~
are all string literals. The corresponding commands for c
d
and ~
means duplicate the top of the main stack, pop the top of the main stack, and pop the top of the main stack and push to the input stack, respectively. For this challenge, input stack does not affect output and is not important, hence we can say d
and ~
are identical.
Explanation
It is best to divide the code into several parts and consider them separately.
When it is not tampered with, '''cc
pushes a literal '
and a literal c
to the main stack, and duplicates the top, so the stack would be (from to bottom) c,c,'
.
When not tampered with, '~~
pushes the literal ~
and then pops it (and push to the input stack), which is basically a no-op for the main stack.
When not tampered with, 'dd
pushes the literal d
and then pops it, another no-op for the main stack.
At the end of the program, since no explicit output is done, the top of the main stack will be implicitly printed out.
If the program is running as-is, the final stack is still c,c,'
and will output c
.
If the first part becomes ''cc
, then we have a literal '
, and two copy instructions, the final stack will be ',','
. Given that the two other parts are no-op, the result will be '
.
If the first part becomes '''c
, the result is basically the same with the untampered one, but the c
is not duplicated. So the stack will be c,'
. After two no-op's the top of the stack is c
.
So we can detect radiation in the first part.
The second part and the third part work in exactly the same way. I will take the third part as an example.
If the third part is tampered with, then the first two parts are kept as-is and the stack before running the third part is c,c,'
If the third part becomes 'd
, a literal d
is pushed to the top of the main stack and nothing further is done. The top of the main stack is now d
which will be output.
If the third part becomes dd
, two elements are popped from the main stack and now the top of the stack is '
and is output.
Hence we can detect radiation in the third part. For the same reason we can detect radiation in the second part.
Related, related, related
I missed that line. Shame on me! – Mego – 2018-01-29T08:34:26.007
5"The code will be scored on the number of distinct characters, where the highest amount wins." I expect that most (if not all) solutions will have some form of string somewhere which they can just pad with arbitrary characters without actually changing the solution (so it just comes down to whether your language is restricted to ASCII, extended ASCII or Unicode). – Martin Ender – 2018-01-29T09:17:46.630
ASCII only has 128 characters. – Adám – 2018-01-29T09:54:44.500
3... The sandbox is not perfect. :( / You can just measure "distinct bytes" instead of "distinct characters", because characters are related to encoding and other problems. – user202729 – 2018-01-29T09:57:54.787
Must the original program/function work or can that be a syntax error? – Stewie Griffin – 2018-01-29T13:08:39.673
@StewieGriffin Uh, I'd assume It doesn't matter what the original program does means that it can be a syntax error, however it's not very clear. – Erik the Outgolfer – 2018-01-29T13:24:27.683
can we output the numerical value of the removed byte, or should the output be strictly a character? – Uriel – 2018-01-30T21:21:56.623
when using UTF-8, should we consider a byte missing or a character missing? – Uriel – 2018-01-30T21:22:48.870
@Uriel byte missing. – Jo King – 2018-01-30T21:38:43.203
This should just be code-golf. – mbomb007 – 2018-01-31T17:16:01.067
Can output from a brainfuck program, be the memory dump? :) Makes for an easy solution. – Håvard Nygård – 2018-02-14T11:10:08.177
@HåvardNygård What do you mean? Just to clarify, a program should only output a single byte – Jo King – 2018-02-14T11:59:05.517
@JoKing Does the memory dump of a program, post execution, count as program output? - If it is a single byte – Håvard Nygård – 2018-02-14T20:34:27.060
@HåvardNygård. If you can manage it, go for it. But I'm pretty sure there's no way to do a brainfuck program for this challenge, given you can't have loops. – Jo King – 2018-02-14T21:42:11.483
Smallest codepage wins! – Magic Octopus Urn – 2018-02-14T22:05:52.977
1Can the program take any input? – gggg – 2018-02-15T20:47:59.423
Can the program output a single byte more than one time. Eg
22
oraa
but nota2
? – gggg – 2018-02-15T21:26:59.000@gggg I'll allow it – Jo King – 2018-02-16T05:32:15.390
I really am starting to doubt that there are any answers in 05AB1E that don't use
'
, +200 to anyone who proves me wrong lol. – Magic Octopus Urn – 2018-02-16T16:51:27.457@JoKing what is the tie-breaker? Byte-count? Time posted? – Magic Octopus Urn – 2018-02-16T17:12:10.750
@MagicOctopusUrn Found one! – boboquack – 2018-02-16T22:54:16.843