// Learn more about F# at http://fsharp.net open System open System.Diagnostics let width, height = 12,12 let board = Array2D.init width height (fun x y -> 0) let computeNeighbours x y (board:int[,]) = let getValue (x,y) = let x = (x + width) % width let y = (y + height) % height board.[x,y] [ -1,-1;0,-1;1,-1; -1,0; 1,0; -1,1 ;0,1;1,1; ] |> Seq.map (fun (dx,dy) -> x+dx,y+dy) |> Seq.map getValue |> Seq.sum do //List.append //[4,5;5,5;4,6;6,5;4,6] //[1,2;2,1;2,2;3,1;3,2] [7,7;8,7;9,7;9,6;8,5] |> List.iter (fun (x,y) -> board.[x,y] <- 1) let show (board:int[,]) = for y = 0 to height-1 do for x = 0 to width-1 do let v = if board.[x,y] = 0 then '0' else '1' Console.Write v Debug.Write v Console.WriteLine () Debug.WriteLine "" Console.WriteLine(String('-',width)) Debug.WriteLine(String('-',width)) show board let doGeneration board = board |> Array2D.mapi (fun x y n -> match n, computeNeighbours x y board with | _, 3 -> 1 | n, 2 -> n | _, _ -> 0 ) do let mutable current = board for i = 1 to 10 do show current current <- doGeneration current done