Created
October 24, 2014 13:04
-
-
Save pi8027/31c79e3d78a634b63894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
script=$(cat << EOT | |
{ | |
:loop | |
p | |
s/0 \([^ ]*\)\([01]\) +O/ \1 +O\2/ ; t loop | |
s/1 \([^ ]*\)0 +O/ \1 +O1/ ; t loop | |
s/1 \([^ ]*\)1 +O/ \1 +I0/ ; t loop | |
s/0 \([^ ]*\)0 +I/ \1 +O1/ ; t loop | |
s/0 \([^ ]*\)1 +I/ \1 +I0/ ; t loop | |
s/1 \([^ ]*\)\([01]\) +I/ \1 +I\2/ ; t loop | |
s/ +O// ; t loop | |
s/\(^\|0\) +I/1/ ; t loop | |
s/1 +I/ +I0/ ; t loop | |
s/^ \([^ ]*\) +O/\1/ ; t loop | |
s/^ \([^ ]*0\) +I/\11/ ; t loop | |
s/^ \([^ ]*1\) +I/ \1 +I0/ ; t loop | |
s/0 \([^ ]*\) \*/ \1 \*0/ ; t loop | |
s/ \([^ ]*\)0 \*/ \1 \*0/ ; t loop | |
s/1 \([^ ]*\) \*/ \1 \*0 \1 +O/ ; t loop | |
s/^ [^ ]* \*/0/ ; t loop | |
} | |
EOT) | |
echo '1110 101 +O 10 +O' | sed -e $script | |
echo | |
echo '1110 101 * 110 +O' | sed -e $script | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment