vicuna-13b· LMSYS
Arena Human Preference 55K
Write Conway's Game of Life in HTML, CSS and JavaScript thnx
- User
Write Conway's Game of Life in HTML, CSS and JavaScript thnx
- Assistant
Sure, here's an example implementation of Conway's Game of Life in HTML, CSS, and JavaScript:
HTML:
<!DOCTYPE html> <html> <head> <style> #container { width: 250px; height: 250px; background-color: black; border: 1px solid white; margin: auto; position: absolute; } </style> </head> <body> <div id="container"></div> <script src="life.js"></script> </body> </html>CSS:
#container { display: flex; flex-direction: row; align-items: center; } #container .cell { width: 20px; height: 20px; border: 1px solid white; margin: 5px; }JavaScript (life.js):
const container = document.querySelector('#container'); const cells = Array(25).fill().map(() => Array(25).fill(false)); function updateCells() { for (let i = 0; i < 25; i++) { for (let j = 0; j < 25; j++) { const neighbors = countNeighbors(i, j); cells[i][j] = (cells[i][j] === 25) ? false : neighbors > 2 || neighbors < 2; } } for (let i = 0; i < 25; i++) { for (let j = 0; j < 25; j++) { const x = (i + 1) % 25; const y = (j + 1) % 25; const dx = (x - i) / 25; const dy = (y - j) / 25; cells[i][j] = cells[x][y]; } } drawCells(); } function
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.