7 points · by luminaobscura · 14y ago · 5 comments
For example, on this input:
-10 100
-10 101
-10 102
1000 5
1001 5
1002 5
the output is: -11 101
-9 101
1001 4
1001 6
-10 101
1001 5
Here is the code, for bash or similar shells: > alive.$$
while read cells
do
echo $cells >> alive.$$
set x $cells
x=$2
y=$3
echo $x $((y-1))
echo $x $((y+1))
echo $((x-1)) $((y-1))
echo $((x-1)) $y
echo $((x-1)) $((y+1))
echo $((x+1)) $((y-1))
echo $((x+1)) $y
echo $((x+1)) $((y+1))
done | sort | uniq -c > neighbors.$$
grep '^ *3' < neighbors.$$ | sed -e 's/^ *[0-9].//'
grep '^ *2' < neighbors.$$ | sed -e 's/^ *[0-9].//' > has2.$$
sort alive.$$ -o alive.$$
comm -12 has2.$$ alive.$$
rm has2.$$ neighbors.$$ alive.$$ Must it use variables?
Must it have flow control?
Must it actually compute something?
Must it use non-primitive data structures?
Must it exhibit use of the language’s code organisation features?
These are some of the more generic properties that programs can have....
One suggestion (from David Pearce) was Conway’s Game of Life: a simple simulation of finite automata. This seems like a good demonstration of most of the properties.
It is quite cool, though, to see a common problem solved in such a wide variety of languages.
s/all languages/lots of languages/g