optimized 1dlife
This commit is contained in:
@@ -18,22 +18,15 @@ state="${state//[^0]/1}"
|
||||
slen=$((${#state} - 1)) # length + 4 (temporary padding) - 5
|
||||
|
||||
# complete rule mapping
|
||||
declare -A values=(
|
||||
00000 0 00001 0 00010 0 00011 1
|
||||
00100 0 00101 0 00110 0 00111 1
|
||||
01000 0 01001 1 01010 1 01011 1
|
||||
01100 0 01101 1 01110 1 01111 0
|
||||
10000 0 10001 1 10010 1 10011 1
|
||||
10100 0 10101 1 10110 1 10111 0
|
||||
11000 1 11001 1 11010 1 11011 0
|
||||
11100 1 11101 0 11110 0 11111 1)
|
||||
|
||||
declare -ar values=(0 0 0 1 0 0 0 1 0 1 1 1 0 1 1 0 \
|
||||
0 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1)
|
||||
|
||||
for ((i=0; i<ITERS; ++i)); do
|
||||
state="00${state}00" # pad the current state from both sides
|
||||
newstate=''
|
||||
for ((k=0; k<slen; ++k)); do
|
||||
vidx="${state:k:5}"
|
||||
newstate="${newstate}${values[$vidx]}"
|
||||
newstate="${newstate}${values[$((2#$vidx))]}"
|
||||
done
|
||||
state="$newstate"
|
||||
newstate="${newstate//0/ }"
|
||||
|
||||
Reference in New Issue
Block a user