Add rule110.sed
`rule110.sed` is an executable sed script that calculates the next iteration of rule 110 cellular automaton. E.g. `./rule110.sed <<<0001` outputs `0011`.
This commit is contained in:
21
rule110.sed
Executable file
21
rule110.sed
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/sed -Ef
|
||||
|
||||
# Translate to intermediate step
|
||||
# - Lowercase means previous state was 0
|
||||
# - Uppercase means previous state was 1
|
||||
# - [Aa] means new state is 1
|
||||
# - [Bb] means new state is 0
|
||||
# - Assume edges are 0
|
||||
:a
|
||||
s/([B1])1([B1$])/\1B\2/g # 111 -> 0
|
||||
t a
|
||||
:b
|
||||
s/([B1])0([B1$])/\1a\2/g # 101 -> 1
|
||||
t b
|
||||
:c
|
||||
s/([a0^])0([B1$])/\1a\2/g # 001 -> 1
|
||||
t c
|
||||
|
||||
# Translate to final results
|
||||
s/a/1/g
|
||||
s/B/0/g
|
||||
Reference in New Issue
Block a user