esolang

DAMN COVID-19

A virus crawls from city to city on a map. Only after it has infected every one can it build or destroy.

Hakerh400, 2020 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Test method

Run it

Expected: # # # #

The idea

Hakerh400 made DAMN COVID-19 in 2020. The input is a map of cities, #, with one infected city, *, and all cities joined into one island. The program steers the virus. Until every city is infected it can only step onto cities, and its only memory is a tape of a few bits, so it has to find its way around the island like a finite state machine. Once every city is infected it may also cross empty tiles, jump back to where it started and add or remove cities, which gives it unbounded memory. The output is the map that is left.

Read the story

The specification says the language is Turing complete exactly when a finite state machine can visit every city of any island, and it lists the class as unknown.

The machine

The program starts with the size of the tape. All its bits start at 0.

CodeDoes
^ v < >Move the virus one tile, onto a city only until all are infected
~< ~>Move along the tape
!Flip the bit
@Remove the city here, or add one; only once all are infected
%Go back to the start; only once all are infected
?c(...) ?c(...):(...)If, and if else
?c{...}While

A condition c is # (a city at the pointer), ^ v < > (a city next to it), . (the bit is 1) or @ (every city is infected), and ?!c turns it around.

The specification lets the interpreter scatter a random number of new cities over the map first, a number that may be 0. This implementation adds none, so a run always repeats. The tape wraps around at its ends, as the second example needs. Its walk matches the step by step trace in all 78 moves.

Example

The first example walks left and right until every city is infected, then deletes them all.

The first example walks left and right until every city is infected, then deletes them all. Its ending deletes every second city instead.

The second example keeps a direction in two bits of a 3 bit tape and follows the edge of the island. It infects any island without loops and leaves the map as it was.

Expected: ### # # ####### # # ########

Further

Also in Spatial (2D and up)

Write your own in Run Convert a program from DAMN COVID-19

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: damn-covid-19.

Command line

shib run damn-covid-19 -e '3?!@{?!.{~>?!.(~>?!.(?^(^!~>!):(!~<!~<)):(?>(>!~<!~<!):(!~>))):(~>?!.(?v(v!~>!):(!~<!~<)):(?<(<!~<!~<!):(!~>)))}!}' --input '       ######  
        #      
      #######  
  #####      # 
### #   #######
    #   *      
   #########   '
shib manual damn-covid-19

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/damn-covid-19.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org