Skip to content

Instantly share code, notes, and snippets.

@ytaki0801
Last active February 1, 2023 03:29
Show Gist options
  • Save ytaki0801/ff879c097be0d661bea1405809be9774 to your computer and use it in GitHub Desktop.
Save ytaki0801/ff879c097be0d661bea1405809be9774 to your computer and use it in GitHub Desktop.
Elementary Cellular Automata in POSIX Shell, Rules from 0 to 255
#!/bin/sh
cnum=180; step=80;
rule=0
while [ $rule != 256 ]; do
b=$rule; for x in 0 1 2 3 4 5 6 7; do export r$x=$((b%2)) b=$((b/2)); done
i=0; while [ $i != $cnum ]; do export c$i=0 i=$((i+1)); done
export c$((cnum/2))=1
clear
s=0
while [ $s != $step ]; do
i=0
while [ $i != $cnum ]; do
case $((c$i)) in 0) printf " ";; *) printf "*";;
esac; i=$((i+1))
done
echo
i=0
while [ $i != $cnum ]; do
case $i in 0) x=0;; *) x=$((c$((i-1))));; esac
y=$((c$i))
case $i in $((cnum-1))) z=0;; *) z=$((c$((i+1))));; esac
export cn$i=$((r$((x*4+y*2+z)))) i=$((i+1))
done
i=0; while [ $i != $cnum ]; do export c$i=$((cn$i)) i=$((i+1)); done
s=$((s+1))
done
sleep 0.1
rule=$((rule+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment