| Bytes | Lang | Time | Link |
|---|---|---|---|
| 338 | Python 2 | 210731T110751Z | Jakque |
| nan | R | 210731T082542Z | Dominic |
| nan | Python 2 | 210731T101401Z | ovs |
| 137 | Backhand | 210731T024950Z | Jo King |
Python 2, 338 bytes, score = 16 11
exec"aabb==''''''iimmppoorrtt ssyyss;;dd==cchhrr((3399))**33;;ssyyss..ssttddoouutt..wwrriittee((''eexxeecc''''%%cc''%%3344++''''..jjooiinn((ii**22ffoorr ii iinn''aabb==''++dd++aabb++dd++'';;aa==aabb[[::4466]]++aabb[[5533::]];;eexxeecc aa''))++''bb%%cc[[::::22]]''%%3344))'''''';;aa==aabb[[::4466]]++aabb[[5533::]];;eexxeecc aab"[::2]
when any of the char of inside the string is removed, then the first " is removed
How it works :
- for a string like
"aabbccddee", when we take one char every two char, we get"abcde"even if it has a missing char.
I then applied this principle on the quine a="print('a=%r;exec(a)'%a)";exec(a)
- if the code has a deletion: the end of the string will be
exec ainstead ofexec abwhich result of the deletion of the first".
Note: I could reduce the number of byte by using input instead of sys.stdout.write to print without a newline but it would throws an error (still valid but uglyer)
Python 3.8 (pre-release), 187 bytes, score = 16
exec(a:="pprriinntt((eenndd==''eexxeecc((aa::==''++((''%%rr[[::::22]]))''%%((''''..jjooiinn((ii**22ffoorr ii iinn aa iiff''##''!!==ii))++''##''))))[[aa[[--11]]====''))''::]]))#"[::2])
R, 58 bytes; score = 58-2 = 56
'->a;cat(sQuote(a),a,2*11)#' ->a;cat(sQuote(a),a,2*11)# 22
Pretty boring, but now scores better than my original version (below).
Either of the 1 characters near the end of the code can be deleted, resulting in deletion of one of teh two 2 characters at the end of the output.
R, 271 253 bytes; score = 101 253-160 = 93
(Previous solution, better optimized for the initial 'code length divided by changeable characters' scoring method)
a=';`+`=nchar;`!`=sQuote;cat("a=",!(c<-`if`(+a>+b,a,b)),";b=",!c,c,"#"[a==b],sep="")';b=';`+`=nchar;`!`=sQuote;cat("a=",!(c<-`if`(+a>+b,a,b)),";b=",!c,c,"#"[a==b],sep="")';`+`=nchar;`!`=sQuote;cat("a=",!(c<-`if`(+a>+b,a,b)),";b=",!c,c,"#"[a==b],sep="")#
If any of the two sets of 80 single-quoted non-# characters are removed from the code, the final # character is removed from the output.
Python 2, score: 206 - 178 = 28
If you remove any single character in the two long strings, the first " in the output is omitted.
a="print('a=%r,%r;exec max(a,key=len)'%((max(a,key=len),)*2)).replace(chr(34),'',a[0]!=a[1])","print('a=%r,%r;exec max(a,key=len)'%((max(a,key=len),)*2)).replace(chr(34),'',a[0]!=a[1])";exec max(a,key=len)
Based on this quine, this executes the longer, and therefore unmodified, string of a.
Backhand, Score 0, 137 bytes
""###:::[[[:::::::::)))))))))888999***EEE666***333+++ssscccjjjlll222%%%]]]333***xxx(((sss~~~rrr~~~''' sss---***333aaa000~~~rrr:::rrrHHH
I've included the interpreter here because the version on TIO is a bit out of date (in this case missing the instructions Equal and skip). E could be compensated for with -!, but you'd need to do a lot of fiddling around with jump to replace skip.
This code outputs itself if no changes are made, the original code missing a trailing H if any character other than H is removed, and if the H is removed, it removes the leading " instead.
Explanation
Basically, each instruction is duplicated three times (except for the leading ", which is only doubled). This is used as a form of radiation hardening, so that even if one instruction is removed, it can still regenerate it from the others. Backhand is especially good at this, since by default it executes every third instruction. Removing the duplicates, we get:
"#:[:::)))89*E6*3+scjl2%]3*x(s~r~' s-*3a0~r:rH
" Push the rest of the code, forwards then backwards
# No-op
:[ Dupe the # and decrement it to get "
Start loop
::: Make three copies of the top of stack
))) Push those to the other stack
89*E Is the value a `H`?
3+scj If not, jump back to the start of the loop
End loop
l2%]3* If the length of the pushed code is odd (i.e. a character is missing)
x( Flip to the other stack
s~ and pop the H if so
r~ Reverse the stack and pop the extra "
' s Skip forwards 32 spaces, i.e. the instruction three from the end
This is the H if all Hs are still present, so it halts and outputs
:r Otherwise, reverse and duplicate the H
~r And pop the "
s-*3a0 And skip back to the H to halt and output