about summary refs log tree commit diff stats
path: root/html/027call_ingredient.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 4709Kartik Agaram2018-10-171-6/+6
* 4588Kartik Agaram2018-09-221-2/+2
* 4539Kartik Agaram2018-09-071-6/+6
* 4447Kartik Agaram2018-07-271-70/+72
* 4243Kartik Agaram2018-05-121-3/+3
* 4239Kartik Agaram2018-05-081-6/+6
* 4228Kartik K. Agaram2018-03-151-1/+1
* 4199Kartik K. Agaram2018-01-251-60/+59
* 4161Kartik K. Agaram2017-12-151-9/+9
* 4155Kartik K. Agaram2017-12-071-21/+21
* 4134 - 'input' = 'ingredient'Kartik K. Agaram2017-12-031-146/+149
* 4102Kartik K. Agaram2017-11-011-17/+17
* 3990Kartik K. Agaram2017-09-031-1/+1
* 3927Kartik K. Agaram2017-06-191-5/+5
* 3900Kartik K. Agaram2017-06-021-17/+17
* 3897 - various updates to documentationKartik K. Agaram2017-05-291-11/+11
* 3877Kartik K. Agaram2017-05-261-2/+2
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-4/+5
* 3761Kartik K. Agaram2017-03-071-57/+58
* 3750Kartik K. Agaram2017-03-021-6/+6
* 3749Kartik K. Agaram2017-03-021-6/+6
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-23/+23
* 3710Kartik K. Agaram2016-12-261-188/+188
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-192/+216
* 3667Kartik K. Agaram2016-11-111-2/+3
* 3544Kartik K. Agaram2016-10-221-1/+1
* 3543Kartik K. Agaram2016-10-221-4/+2
* 3524Kartik K. Agaram2016-10-201-2/+2
* 3431Kartik K. Agaram2016-09-301-12/+13
* 3395Kartik K. Agaram2016-09-171-14/+14
* 3315Kartik K. Agaram2016-09-101-6/+10
* 3219Kartik K. Agaram2016-08-171-0/+1
* 3158Kartik K. Agaram2016-07-271-2/+2
* 3102Kartik K. Agaram2016-07-051-1/+2
* 2996Kartik K. Agaram2016-05-211-7/+7
* 2866Kartik K. Agaram2016-04-251-0/+221
"w"> }, 0); } function step(grid) { // Use map to iterate over each cell in the grid and calculate the next state based on the rules of the game return grid.map((row, x) => row.map((cell, y) => { // Count the number of live neighbors for the current cell const neighbors = countNeighbors(grid, x, y); // Apply the rules of the game to determine the next state of the cell // If the cell has 3 live neighbors or has 2 live neighbors and is already alive, it stays alive // Otherwise, it becomes dead return neighbors === 3 || (neighbors === 2 && cell) ? 1 : 0; }) ); } function printGrid(grid) { grid.forEach(row => console.log(row.map(cell => cell ? '🟢' : '⚪️').join(''))); console.log('\n'); } function simulate(initial, steps) { let grid = initial; Array.from({ length: steps }).forEach(() => { printGrid(grid); grid = step(grid); }); } const initialBoard = [ [0, 1, 0], [0, 0, 1], [1, 1, 1], [0, 0, 0], ]; simulate(initialBoard, 10); const rpentomino = [ [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]; // simulate(rpentomino, 10); // big glider const bigGlider = [ [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ]; // simulate(bigGlider, 10); const randomBoard = Array.from({ length: 22 }, () => Array.from({ length: 22 }, () => Math.round(Math.random())) ); simulate(randomBoard, 50);