about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--swift/life/Sources/main.swift13
1 files changed, 11 insertions, 2 deletions
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..<rows).map { _ in
+        return (0..<cols).map { _ in
+            return Int.random(in: 0...1)
+        }
+    }
+}
+simulate(board: randomBoard(), generations: 10)
\ No newline at end of file
'>98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158