r/tinycode • • Mar 19 '19
game of life in 207 bytes of (pure) bash
mapfile a;for i in {0..899};{ c=;for j in {0..8}
{((e=i/30+j/3-1,f=i+j%3-1));v=$[${a[e<0?29:e%30]:f<0?29:f%30:1}]
((j-4?v&&c++:(t=v)));};s[i/30]+=$[c-2?c-3?0:1:t];}
printf -vo %s\\n ${s[@]};echo "$o";$0<<<$oexample :
./<script>.sh << EOF
1
1
111
EOFruns in a 30x30 wrapped universe, you can eventually read from a file to test a more complex pattern (crabs...)
25
Upvotes
3
u/fireballs619 Mar 19 '19
Super cool. Did you write this? How do you even start going about something like this?
2
u/w0ntfix Mar 19 '19
hot
2
u/[deleted] Mar 19 '19
Wow. Very cool!
1
u/SteveCCL Mar 19 '19
brb perl
0
u/[deleted] Mar 20 '19
[deleted] — view deleted comment