Guest User

Untitled

a guest
Dec 9th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. -module(gol).
  2. -compile(export_all).
  3.  
  4. lives(2,true) ->
  5. true;
  6. lives(3,_) ->
  7. true;
  8. lives(_,_) ->
  9. false.
  10.  
  11. intersect_lists(A,B) ->
  12. sets:to_list(sets:intersection(sets:from_list(A), sets:from_list(B))).
  13.  
  14. neighbors(Xin,Yin, World) ->
  15. Ns = [{X+Xin, Y+Yin, true} || X <- [-1,0,1], Y <- [-1,0,1] ],
  16. length(intersect_lists(World, Ns))
  17. - length([ true || {A,B,true} <- World, A == Xin, B == Yin ]).
  18.  
  19. transmute_world(World) ->
  20. [ {X, Y, gol:lives(gol:neighbors(X,Y, World), Alive)} || {X,Y,Alive} <- World ].
Add Comment
Please, Sign In to add comment