Skip to content

Instantly share code, notes, and snippets.

@jszmajda
Created September 18, 2011 20:22
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jszmajda/1225511 to your computer and use it in GitHub Desktop.
Save jszmajda/1225511 to your computer and use it in GitHub Desktop.
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