14
\$\begingroup\$

Your task is to create a program where if any one character is deleted, it will detect which character was deleted and then re-insert the deleted character in its own source file.

For instance, if your program is RadiationHardened and it is modified to RadiaionHardened, then your program must output that the 5th byte (0-indexed) was modified and then the program source must be RadiationHardened immediately after execution.

Notes and rules

  • You may assume that exactly one character was deleted in the source code before execution. Behavior for the unmodified program is undefined.
  • You may assume the changed byte will be deleted, not transposed, inserted, or replaced.
  • In the case of a run of multiple of the same character, you may report either the first or the last index of the run, but be consistent about which you use. For example baaad being deleted to baad can report either 1 or 3 (zero indexed), but must be the same throughout the entire program.
  • You do not need to write out the entire source to its own file. You need only re-insert the deleted byte.
  • Unlike the typical rules for radiation-hardened quines, detecting the changed byte from reading the program's own source code is fair game.
  • You can output the changed byte index through any reasonable format. Be consistent about whether it is 0-indexed or 1-indexed or any other notation. You may even output a number within a template string.

This is so the shortest program wins.

Good luck!

EDIT1: changed requirement from replacement to deletion

EDIT2: added rule for runs of duplicates

\$\endgroup\$
11
  • 4
    \$\begingroup\$ This is a lot harder than handling arbitrary deletions. Most non-esolangs are obviously out (it's usually impossible to write any program that remains syntactially valid under any one-byte modification). Even Fungeoids are mostly thwarted (they can't do anything if the 0th byte is changed into a quit program command). I thought maybe one of two IPs could survive in something like Fission but its * command kills all of the IPs. Cardinal can't do it either, because of @. \$\endgroup\$
    – lynn
    Commented Feb 23, 2019 at 19:50
  • \$\begingroup\$ This might be turned into a code-challenge where each program is allowed to declare a list of bytes that are protected against radiation (but no more than -- say -- 50% of the total size). A simple scoring system could be to count each radiation-protected byte as 10 bytes, or something like that. \$\endgroup\$
    – Arnauld
    Commented Feb 23, 2019 at 22:48
  • \$\begingroup\$ (But that may lead to some trivial and not very interesting answers.) \$\endgroup\$
    – Arnauld
    Commented Feb 23, 2019 at 22:54
  • 1
    \$\begingroup\$ @JoKing, reporting either as missing is fine, as long as it's consistent. \$\endgroup\$
    – Beefster
    Commented Feb 25, 2019 at 16:56
  • 2
    \$\begingroup\$ "You may require the file to be named a certain name and be run from a specific directory" - be careful, someone can just require that the filename be the correct program... \$\endgroup\$
    – ASCII-only
    Commented Feb 28, 2019 at 22:55

2 Answers 2

11
\$\begingroup\$

Befunge-98 (FBBI), 344 296 248 bytes

20020xxnngg33%%!!2200gg''00--3300gg33%%!!4400gg55%%!!22kk++55##rr55kk::00gg\\11pp00gg\\11++11pp22++00::pp00gg\\11++00gg--!!zz!!22**++00::gg00gg8844**--!!55++jj..''gg::00rr00::gg\\--..''220011''0011::''002211''223311''00441144kkppgg11001100::99oo@@

Try it online!

Verification!

Befunge-98 is the first esoteric language that I could find that was both 2D and had file output. This is a full solution (with a trailing newline) stored in a file named as a tab character. It outputs as 0-indexed, and outputs the first index in a run of characters (though there's only ever pairs).

There's a few golfs to be made, especially as there are 15 no-ops in the code, now just one no-op! I will be working on making this shorter, with the goal of getting to or below 200 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ Oh wow! I didn't think this was possible \$\endgroup\$
    – MilkyWay90
    Commented Mar 1, 2019 at 2:36
6
\$\begingroup\$

Unefunge-98 (PyFunge), 118 bytes

22xx00##rr33kk::gg\\11--pp22++00ppgg\\11++gg--!!zz!!22**--00gg::gg8844**--!!22++jj##''rr++..gg''2200pp0011--00::99oo@@

Try it online!

Verification!

While golfing my Befunge-98 answer, I realised I could save some bytes by porting it over to Unefunge, since I would only have to worry about the one dimension rather than the two. This also opened up a lot of possible shortcuts and golfs, which made the new solution much much smaller.

Explanation (de-duplicated):

2x        Set the delta of the movement to 2
          This means the pointer moves 2 cells every step
          This will also initialise a counter as 2 (unless a 2 has been removed)
  0       Create the cell counter  (This will be stored at cell 0)
   #r     Enter the loop
     3k:                 Create 3 more copies of the counter
        g                Get the cell at the counter's position
         \1-p            Put it in the cell before that position
             2+0p        Add 2 to the counter and put it in cell 0
                 g       Get the cell at the counter's position
                  \1+g   Get the next cell
                      -!z!2*      If they are identical, push two, else 0
                            --    Subtract it from the total counter
                              0g:g84*-!   If the next character is a space
                                       2+j  r   Exit loop
                                         j#'    Else jump back to the start

Once the loop is over
+      Add the negative counter to the total counter
 .     And print
   '20p          Replace the 2 in cell 0 that was overwritten
             o   Write to a file named
            9    Tab
       01-       The cells from -1 to
  g              The total number of cells
              @  And exit the program
\$\endgroup\$

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.