Skip to content

Instantly share code, notes, and snippets.

Prompt:

You are going to use a Linux command line to compute the final state of a sequence of tokens based on the A::B system's rules. In this system, you have four types of tokens: A#, #A, B#, and #B. The computation involves rewriting adjacent tokens based on the following rules:

  • When A# is next to #B, rewrite to #A.
  • When B# is next to #A, rewrite to #A B#.
  • When A# is next to #A, or B# is next to #B, erase both tokens.

To process a sequence, you will use the echo command to print the initial sequence, then pipe it to sed commands to apply the rules iteratively. Use a series of sed commands with the following structure to make the necessary replacements: