From bd4028356efaf51b82cc71d3ddd15db327106706 Mon Sep 17 00:00:00 2001 From: elioat Date: Wed, 19 Jun 2024 17:40:23 -0400 Subject: * --- swift/life/Sources/main.swift | 50 +++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'swift/life') diff --git a/swift/life/Sources/main.swift b/swift/life/Sources/main.swift index 4b3e7a6..e010b94 100644 --- a/swift/life/Sources/main.swift +++ b/swift/life/Sources/main.swift @@ -2,7 +2,6 @@ import Foundation let rows = 10 let cols = 10 -var board = Array(repeating: Array(repeating: 0, count: cols), count: rows) func printBoard(_ board: [[Int]]) { board.forEach { row in @@ -40,14 +39,43 @@ func nextGeneration(_ currentBoard: [[Int]]) -> [[Int]] { } } -board[1][2] = 1 -board[2][3] = 1 -board[3][1] = 1 -board[3][2] = 1 -board[3][3] = 1 - -for _ in 0..<10 { - printBoard(board) - board = nextGeneration(board) - sleep(1) // FIXME: figure out how to sleep for periods shorter than a full second +func simulate(board: [[Int]], generations: Int) { + var currentBoard = board + for _ in 0..