Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Game of Life in Erlang

Conway's Game of Life in Erlang, in 2 hours, with 0 Erlang experience, in 20 lines of code.

1337 h4x0rs:

  • @jszmajda
  • @ngauthier
  • @ericoestrich
  • @danivovich
  • @kafuchau
-module(gol).
-compile(export_all).
lives(2,true) ->
true;
lives(3,_) ->
true;
lives(_,_) ->
false.
intersect_lists(A,B) ->
sets:to_list(sets:intersection(sets:from_list(A), sets:from_list(B))).
neighbors(Xin,Yin, World) ->
Ns = [{X+Xin, Y+Yin, true} || X <- [-1,0,1], Y <- [-1,0,1] ],
length(intersect_lists(World, Ns))
- length([ true || {A,B,true} <- World, A == Xin, B == Yin ]).
transmute_world(World) ->
[ {X, Y, gol:lives(gol:neighbors(X,Y, World), Alive)} || {X,Y,Alive} <- World ].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment