From 0ae86922893f8697ffc3349714671d884748c2d7 Mon Sep 17 00:00:00 2001 From: elioat Date: Thu, 20 Jun 2024 21:34:01 -0400 Subject: * --- swift/life/Sources/main.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'swift/life') diff --git a/swift/life/Sources/main.swift b/swift/life/Sources/main.swift index 72b1b49..3bd47cd 100644 --- a/swift/life/Sources/main.swift +++ b/swift/life/Sources/main.swift @@ -16,7 +16,7 @@ func printBoard(_ board: [[Int]]) { // Are these comments enough for a blog post? func countLiveNeighbors(_ board: [[Int]], x: Int, y: Int) -> Int { // All of the possible directions to check for live neighbors - let directions = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] + let directions: [(Int, Int)] = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] // Iterate over the directions and count live neighbors return directions.reduce(0) { count, dir in @@ -104,4 +104,13 @@ rpentomino[3][5] = 1 rpentomino[4][3] = 1 rpentomino[4][4] = 1 rpentomino[5][4] = 1 -simulate(board: rpentomino, generations: 22) \ No newline at end of file +simulate(board: rpentomino, generations: 22) + +func randomBoard() -> [[Int]] { + return (0..