24
1
The task here is pretty simple. You should write a program that takes a string as input and outputs it (that is a cat program).
Additionally when the \$n\$th byte of your program is removed (without replacement) the augmented program should take a string as input and remove the \$n\$th character. If the input to your augmented program is less than \$n\$ characters long it should return it as is. For example the python program
x = input()
if "y" == "y":
print(x)
else:
print(x[:16] + x[17:])
will remove the \$17\$th character if its \$17\$th byte is removed (the first y
).
Scoring
Your answer's score will be the number of bytes for which removal does not cause the program to remove the corresponding byte. With better score being lower.
In our example above the total length is 68 bytes, with one byte (the \$16\$th one) augmenting the program correctly. That leaves a score of 67 bytes.
If the program were modfied to work in two places like so:
x=input()
u="az"
if u!="az":x=x[:13+(u<"c")]+x[14+(u<"c"):]
print(x)
Where removing the \$14\$th and \$15\$th characters (a
and z
) work properly. The score is 66 bytes or 68 - 2, since the program is 68 bytes long but two of those bytes work properly.
Rules and clarifications
There must be at least one byte which can be removed that causes the program to remove the corresponding character in the input. This means a cat program on its own is not a valid submission.
Only one byte will be removed at a time. You do not have to worry about what happens when multiple bytes are removed from your program at the same time.
You should support strings using printable ascii characters in addition to all characters that appear in your program itself. Input containing anything else is undefined behavior.
May we work on arrays of characters instead of strings? (For languages for which it's not the same thing.) – Arnauld – 2019-12-14T16:33:25.810
2@Arnauld This challenge asks for a complete program, I chose this because I feel that source layout doesn't play very nicely with functions. As a result I am pretty sure that input will have to be taken as a string. – Post Rock Garf Hunter – 2019-12-14T16:35:00.010
@game0ver I'm not sure what you mean by variable here. Could you clarify the question. – Post Rock Garf Hunter – 2019-12-14T16:35:23.863
@game0ver I am still unsure of what you mean. What is
a
here, is the referencing a specific example? – Post Rock Garf Hunter – 2019-12-14T16:41:51.433@game0ver I still do not known what is meant by
u
. – Post Rock Garf Hunter – 2019-12-14T16:45:44.790In your example you set
u='az'
and depending on those characters the input gets trimmed, so instead of using characters can we use index like 2,3 etc...? – game0ver – 2019-12-14T16:45:58.797@game0ver Your code can be any sequence of bytes, the process is agnostic to what the code is doing. You could set
u=8
, but I'm not sure why you would want to, if either the8
or theu
is removed then the program will error. – Post Rock Garf Hunter – 2019-12-14T16:48:32.853Is it OK if the output includes extra non-printable characters (e.g. null bytes)? – Robin Ryder – 2019-12-15T20:49:02.143
@RobinRyder An extra newline at the end is ok. – Post Rock Garf Hunter – 2019-12-15T21:01:03.690
@WheatWizard But non-printable characters are not? – Robin Ryder – 2019-12-15T21:07:04.887
@RobinRyder I would consider the newline to be a non-printable characters,but I don't think extra null bytes are acceptable. – Post Rock Garf Hunter – 2019-12-15T21:19:00.693
One more complicated scoring formula that could have worked pretty well is
n+(n-r)*100/n
, withn
= size in bytes andr
= number of removable characters. – Arnauld – 2019-12-17T17:04:36.000@Arnauld I'm pretty happy with the current scoring formula as it is. – Post Rock Garf Hunter – 2019-12-17T17:14:16.583