diff options
-rw-r--r-- | life.txt | 17 | ||||
-rw-r--r-- | swift/life/Sources/main.swift | 8 | ||||
-rw-r--r-- | ts/bun/index.ts | 13 |
3 files changed, 37 insertions, 1 deletions
diff --git a/life.txt b/life.txt new file mode 100644 index 0000000..0428310 --- /dev/null +++ b/life.txt @@ -0,0 +1,17 @@ +# Conway's Game of Life + +I like to implement Conway's Game of Life. Here are some notes on my general approach to doing that. + +## Rules + +- The universe is an infinate 2d plain of equally sized cells +- The univsrse's state exists as discrete snap-shots of time, 1 snap-shot is a generation +- Every cell has exactly 2 states, live and dead +- A cell must be in exactly 1 state at a time, either living or dead +- A cell's neighbors are considered to be all adjacent cells +- Any cell with less than 2 live neighbors dies +- Any cell with 2 or 3 live neighbors continues to the next generation +- Any cell with more than 3 live neighbor dies +- Any dead cell with 3 neighbors becomes a living cell + + diff --git a/swift/life/Sources/main.swift b/swift/life/Sources/main.swift index e010b94..b27bcba 100644 --- a/swift/life/Sources/main.swift +++ b/swift/life/Sources/main.swift @@ -79,3 +79,11 @@ toad[4][3] = 1 toad[4][4] = 1 toad[4][5] = 1 simulate(board: toad, generations: 5) + +var rpentomino = Array(repeating: Array(repeating: 0, count: cols), count: rows) +rpentomino[3][4] = 1 +rpentomino[3][5] = 1 +rpentomino[4][3] = 1 +rpentomino[4][4] = 1 +rpentomino[5][4] = 1 +simulate(board: rpentomino, generations: 100) \ No newline at end of file diff --git a/ts/bun/index.ts b/ts/bun/index.ts index 51938d2..f1a0d95 100644 --- a/ts/bun/index.ts +++ b/ts/bun/index.ts @@ -28,6 +28,14 @@ const toad: Grid = [ [0, 0, 0, 0, 0, 0] ]; +const rpentomino: Grid = [ + [0, 0, 0, 0, 0, 0], + [0, 0, 0, 1, 1, 0], + [0, 0, 1, 1, 0, 0], + [0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 0, 0] +]; + console.log('Initial:'); simulate(initial, 5); @@ -35,4 +43,7 @@ console.log('Flyer:'); simulate(flyer, 5); console.log('Toad:'); -simulate(toad, 5); \ No newline at end of file +simulate(toad, 5); + +console.log('R-pentomino:'); +simulate(rpentomino, 22); \ No newline at end of file |