nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free run
OpenRouter · OpenCode 2.2.7 · every run of this model · uwu · 2026-11-13
Run nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free on your computer to see the two side by side.
A full run: 50 tasks, 82 points
- Score
- 4,500 Gold Speed times the share of points, times 100. Platinum starts at 6,000: 91.2 tok/s with these answers. How scores work68.3 tok/s × 65.9% of points
- Bronze0
- Silver1,500
- Gold3,000
- Platinum6,000
- Diamond10,000
Not on the leaderboard: it ran through a hosted service, so it is not on a computer board. Leaderboard
- Tasks passed
- 38/50
- Points
- 54/82Harder tasks count 3. How scores work
- Tokens
- 205,60032,554 read, 173,046 written.
- Speed
- 68.3 tok/sTokens a second, as the runner measured it. The site checks only that the machine could reach it. How speeds are checked
- Summarizing 2/5
- Extracting 5/5
- Following instructions 4/5
- Reasoning 5/5
- Reading code 4/4
- Using tools 5/5
- Building pages 5/5
- Building games 0/4
- Building apps 0/4
- Writing code 3/3
- Fixing code 2/2
- Planning and data 3/3
Run details
Flag this run
Failed 12
One-sentence summaryFailed
431 tokens: 111 read, 320 written · 4 s · 75.5 tok/s
Summarize this in one sentence of at most 30 words. Starting August 3, the Thornbury Public Library will open at 6:45 a.m. instead of 9:50 a.m. on weekdays. The change follows a survey in which 50% of respondents asked for earlier hours. Weekend hours stay the same. The library will hire two part-time staff to cover the extra time, paid for by a county grant.
Starting August 3, Thornbury Library opens weekdays at 6:45 a.m. (instead of 9:50 a.m.) after a 50% survey vote, hiring two part‑time staff funded by a county grant, while weekend hours remain unchanged.
Meeting notes in three bulletsFailed
1,001 tokens: 196 read, 805 written · 14 s · 56.6 tok/s
Summarize these meeting notes as exactly three bullet points, each at most 20 words. Keep only the decisions and ownership changes that matter. Output only the bullet points. Weekly sync, design team. Present: Zara, Jules, Priya, Mei. - Priya reported that the payment provider fixed the export bug; no action needed. - The launch date moves from October 13 to October 20 because the legal review is taking longer. - Mei showed the new onboarding screens. Everyone liked them. Small copy changes only. - The marketing budget of $60,000 was approved by finance on Saturday. - Zara will own end-to-end testing from now on; Jules hands over the test plan by Tuesday. - Next sync is moved to Monday at 09:15. - Coffee machine on floor 6 is broken again.
- Launch date moved to October 20 because legal review is delayed. - Finance approved $60,000 marketing budget; Zara takes ownership of end‑to‑end testing. - Jules will hand over the test plan by Tuesday; next sync set for Monday at 09:15.
Faithful summary of a studyFailed
477 tokens: 141 read, 336 written · 5 s · 61.5 tok/s
Summarize this in at most 50 words. Keep the key numbers. Do not add anything the text does not say. In a randomized trial, 960 adults with chronic migraine took either Soltide or a placebo for 10 weeks. Those on Soltide had 3.9 fewer headache days per month on average, compared with 0.8 fewer days for placebo. Fatigue was the most common side effect, reported by 12% of the drug group. The authors note the trial lasted only 10 weeks and call for longer studies before any recommendation is made.
In a 10‑week, 960‑person randomized trial, Soltide reduced migraine days by 3.9 per month versus 0.8 with placebo; 12% reported fatigue. Authors note the short duration and urge longer studies before recommending it.
Sort a listFailed
157 tokens: 52 read, 105 written · 1 s · 71.2 tok/s
Sort these words alphabetically, ignoring case. Output only the sorted words, on one line separated by commas: Onion, corn, squash, Carrot, rice.
corn, carrot, onion, rice, squash
Build 2048Failed
17,757 tokens: 457 read, 17,300 written · 4 min 46 s · 60.4 tok/s
Build the game 2048 as one web page, playable with the arrow keys, with the board drawn on the page. In <script id="game">, define createGame() returning an object with move(dir) and state(). dir is "up", "down", "left" or "right". state() returns {board, score, over}: board is 4 rows of 4 numbers, top row first (0 is an empty cell), score is a number, over is a boolean. The rules, exactly: 1. The board starts as this one, then a 2 is put in each of the first two empty cells in reading order (row by row from the top, left to right). The score starts at 0. [4, 0, 0, 8] [0, 16, 0, 4] [32, 2, 0, 0] [0, 0, 0, 16] 2. A move slides every tile as far as it goes toward dir. Two tiles of the same value that meet merge into one tile of their sum, nearest the side they move toward first: moving left, [2,2,2,2] becomes [4,4,0,0] and [2,2,2,0] becomes [4,2,0,0]. A tile made by a merge does not merge again in the same move. 3. Each merge adds the new tile's value to the score. 4. If a move changed the board, a 2 is put in the first empty cell in reading order. A move that changes nothing does nothing. 5. over is true when no move would change the board; then moves do nothing. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>2048</title> <style> body {font-family:Arial,sans-serif; display:flex; flex-direction:column; align-items:center; margin-top:20px;} #board {border-collapse:collapse; margin-bottom:10px;} #board td {width:100px; height:100px; border:1px solid #333; text-align:center; vertical-align:middle; font-size:2em; line-height:100px;} #board td:not(:empty) {background:#fff;} #board td:empty {background:#f0f0f0;} #score {font-size:1.5em; margin-bottom:10px;} #msg {margin-top:10px; font-weight:bold;} </style> </head> <body> <div id="msg"></div> <div id="score">0</div> <table id="board"> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> <script id="game"> function createGame() { // initial board let board = [ [4,0,0,8], [0,16,0,4], [32,2,0,0], [0,0,0,16] ]; // place two 2s in the first two empty cells (reading order) let empties = []; for (let r = 0; r < 4 && empties.length < 2; r++) { for (let c = 0; c < 4; c++) { if (board[r][c] === 0) { empties.push([r, c]); } } } empties.forEach(([r, c]) => { board[r][c] = 2; }); let score = 0; let over = false; function deepCopy(arr) { return arr.map(row => row.slice()); } function move(dir) { if (over) return; let newBoard = deepCopy(board); let changed = false; if (dir === 'left' || dir === 'right' || dir === 'up' || dir === 'down') { if (dir === 'left' || dir === 'right') { // process rows for (let r = 0; r < 4; r++) { let row = newBoard[r]; let list = row.filter(v => v !== 0); let merged = false; let newList = []; if (dir === 'left') { for (let i = 0; i < list.length; i++) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } } else { // right for (let i = list.length - 1; i >= 0; i--) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } newList.reverse(); // restore left‑to‑right order } // fill new row with zeros let newRow = new Array(4).fill(0); if (dir === 'left' || dir === 'up') { for (let i = 0; i < newList.length; i++) newRow[i] = newList[i]; } else { for (let i = 0; i < newList.length; i++) { newRow[4 - newList.length + i] = newList[i]; } } row = newRow; } } else { // process columns for (let c = 0; c < 4; c++) { let col = []; for (let r = 0; r < 4; r++) col.push(newBoard[r][c]); let list = col.filter(v => v !== 0); let merged = false; let newList = []; if (dir === 'up') { for (let i = 0; i < list.length; i++) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } } else { // down for (let i = list.length - 1; i >= 0; i--) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } newList.reverse(); } // fill new column with zeros let newCol = new Array(4).fill(0); if (dir === 'up' || dir === 'left') { for (let i = 0; i < newList.length; i++) newCol[i] = newList[i]; } else { for (let i = 0; i < newList.length; i++) { newCol[4 - newList.length + i] = newList[i]; } } for (let r = 0; r < 4; r++) { newBoard[r][c] = newCol[r] || 0; } } } // check if the board changed for (let r = 0; r < 4; r++) { for (let c = 0; c < 4; c++) { if (newBoard[r][c] !== board[r][c]) { changed = true; break; } } if (changed) break; } if (changed) { // place a new 2 in the first empty cell (reading order) let placed = false; for (let r = 0; r < 4 && !placed; r++) { for (let c = 0; c < 4; c++) { if (newBoard[r][c] === 0) { newBoard[r][c] = 2; placed = true; break; } } } board = newBoard; over = false; } else { over = true; } } return { board, score, over }; } function state() { return { board: deepCopy(board), score: score, over: over }; } return { move, state }; } </script> <script> /* wiring */ const game = createGame(); function render() { const { board, score, over } = game.state(); const table = document.getElementById('board'); for (let r = 0; r < 4; r++) { for (let c = 0; c < 4; c++) { const cell = table.rows[r].cells[c]; const val = board[r][c]; cell.textContent = val === 0 ? '' : val; cell.style.background = (val === 0) ? '#f0f0f0' : '#fff'; } } document.getElementById('score').textContent = score; document.getElementById('msg').textContent = over ? 'Game over' : ''; } // initial render render(); // key handling window.addEventListener('keydown', e => { let dir; if (e.key === 'ArrowUp') dir = 'up'; else if (e.key === 'ArrowDown') dir = 'down'; else if (e.key === 'ArrowLeft') dir = 'left'; else if (e.key === 'ArrowRight') dir = 'right'; else return; const result = game.move(dir); render(); }); </script> </body> </html>Build SnakeFailed
10,155 tokens: 458 read, 9,697 written · 2 min 31 s · 64.4 tok/s
Build Snake as one web page on a 10 by 10 grid, playable with the arrow keys (one key press, one step), with the grid drawn on the page. In <script id="game">, define createGame() returning an object with step(dir) and state(). dir is "up", "down", "left" or "right". state() returns {snake, food, score, over}: snake is a list of [x, y] cells, head first; food is [x, y]; score is a number; over is a boolean. x is the column (0 to 9, left to right), y the row (0 to 9, top to bottom); up is y - 1. The rules, exactly: 1. The game starts with snake [[5, 3], [6, 3], [7, 3]], moving left, food at [3, 6], score 0. 2. step(dir): if dir is the opposite of the current direction it is ignored and the snake keeps going; otherwise dir becomes the current direction. The head moves one cell that way. 3. If the new head cell holds the food, the snake grows: its tail stays. Otherwise the tail cell is freed first. 4. If the new head is off the grid or on a cell of the snake (after rule 3), the game is over: over becomes true and nothing else changes. Once over, step does nothing. 5. Eating adds 1 to the score, and the next food goes to the first empty cell in reading order (row by row from the top, left to right) after the new head's cell, wrapping from [9, 9] to [0, 0]. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Snake</title> <style> #grid { display: grid; grid-template-columns: repeat(10, 30px); grid-template-rows: repeat(10, 30px); border: 2px solid black; width: 300px; height: 300px; } #grid div { width: 30px; height: 30px; background-color: #f0f0f0; } </style> </head> <body> <div id="grid"></div> <script id="game"> function createGame() { let snake = [[5,3],[6,3],[7,3]]; let direction = 'left'; let food = [3,6]; let score = 0; let over = false; const bounds = (x,y) => x>=0 && x<10 && y>=0 && y<10; return { step(dir) { if (over) return; // ignore opposite direction if ((dir==='up' && direction==='down') || (dir==='down' && direction==='up') || (dir==='left' && direction==='right') || (dir==='right' && direction==='left')) { // keep current direction } else { direction = dir; } // compute new head let head = snake[0]; let nx = head[0]; let ny = head[1]; if (direction==='up') ny--; else if (direction==='down') ny++; else if (direction==='left') nx--; else if (direction==='right') nx++; // check bounds if (!bounds(nx,ny)) { over = true; return; } // check food let ate = false; if (nx===food[0] && ny===food[1]) { ate = true; score++; } // remove tail if not eating if (!ate) { snake.pop(); } // add new head snake.unshift([nx,ny]); // self collision if (snake.slice(1).some(c=>c[0]===nx && c[1]===ny)) { over = true; return; } // place new food if ate if (ate) { // find next empty cell after new head in reading order let nx2 = nx, ny2 = ny; let nextX = nx2 + 1; let nextY = ny2; if (nextX > 9) { nextX = 0; nextY++; } if (nextY > 9) { nextX = 0; nextY = 0; } let startIdx = nextY*10 + nextX; outer: for (let offset=0; offset<100; offset++) { let idx = (startIdx + offset) % 100; let y = Math.floor(idx/10); let x = idx % 10; if (!snake.some(seg=>seg[0]===x && seg[1]===y)) { food = [x,y]; break outer; } } // fallback (should not happen) if (!food) { outer: for (let y=0; y<10; y++) { for (let x=0; x<10; x++) { if (!snake.some(seg=>seg[0]===x && seg[1]===y)) { food = [x,y]; break outer; } } } } } }, state() { return {snake, food, score, over}; } }; } </script> <script> const game = createGame(); document.addEventListener('keydown', e => { const dirMap = { ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right' }; if (dirMap[e.key]) { game.step(dirMap[e.key]); } }); </script> </body> </html>Box-pushing puzzleFailed
15,304 tokens: 1,121 read, 14,183 written · 3 min 41 s · 64.3 tok/s
Build a box-pushing puzzle as one web page on an 8 by 7 grid, playable with the arrow keys, with the level drawn on the page. Give the page and its heading the title Box-pushing puzzle. In <script id="game">, define createGame() returning an object with walk(dir) and state(). dir is "up", "down", "left" or "right". state() returns {player, boxes, pushes, steps, solved}: player is [x, y]; boxes is a list of [x, y] sorted by row, then column; pushes and steps are numbers; solved is a boolean. x is the column (0 to 7, left to right), y the row (0 to 6, top to bottom); up is y - 1. The level, row 0 first, 8 characters to a row (a space is empty floor; the outer ring is all wall): ``` ######## ## # # ##### # #+$ .# # $ * # # # ######## ``` # wall, space floor, . goal, $ box, * box on a goal, @ player, + player on a goal. The rules, exactly: 1. The game starts with this level, steps 0, pushes 0 and solved false. Walls and goals never change. 2. walk(dir) moves the player one cell in dir. If that cell is a wall, nothing changes and nothing is counted. A goal is floor, so the player can stand on one. 3. If that cell holds a box, the box moves one cell further in dir and the player takes the box's old cell. This push happens only if the cell beyond the box is empty floor or a goal: not a wall and not another box. Otherwise nothing changes and nothing is counted. 4. A walk that moves the player adds 1 to steps. A push is a walk too, so it adds 1 to pushes as well. 5. solved is true when every box is on a goal. Once solved, walk does nothing. The page: the arrow keys do the same walks as walk(dir), one walk for each key press (a key that repeats while held walks once). Four buttons with data-dir="up", data-dir="down", data-dir="left" and data-dir="right" do the same walks. Label them Up, Down, Left and Right, laid out like the arrow keys: Up above Down, with Left, Down and Right in one row. A button with id="restart", labelled Restart, starts the level over, with steps and pushes back at 0. The board is an element with id="board". It holds one element per cell, 56 in all, row by row from the top, 8 to a row, and nothing else. Each cell has role="img" and an aria-label that names what it holds: wall, empty floor, empty goal, box, box on a goal, you or you on a goal. Every cell except empty floor also shows a visible character as its text, so that a wall, a goal, a box and you can each be seen (the character is yours to choose). Show the steps in an element with id="steps" and the pushes in one with id="pushes", each as a plain number. The status line is an element with id="status". Until the level is solved, it must not say that it is solved (a line such as Not solved yet is fine). Once it is, it says solved, with the number of steps next to the word steps and the number of pushes next to the word pushes, for example: Solved in 12 steps with 3 pushes. A tenth of a second after each key press, button press or Restart, the board, the steps, the pushes and the status line show what state() says. A page may draw on the next animation frame or after a timer. The page must not use eval or Function, must not give a timer a string of text (a timer takes a function), must not add a script element to the page, must not set an event attribute such as onclick from text, and must not make network requests or load anything from another site: no fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon or importScripts, and no image or file from another site. The whole page must be under 65,536 characters, and the script with id="game" under 20,000 characters. Light background; walls dark, goals ringed, boxes and the player easy to tell apart. Tell a box on a goal from one off a goal by a mark or shape, not by colour alone. The two scripts share one global scope, so give the page's copy of the map another name than the logic's (a const MAP in both stops the second script with an error), or wrap the page's script in a function. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Box-pushing puzzle</title> <style> #board {display:grid;grid-template-columns:repeat(8,30px);grid-template-rows:repeat(7,30px);gap:2px;} #board > div {width:30px;height:30px;line-height:30px;text-align:center;font-family:sans-serif;background:#eee;} .wall {background:#000;color:#fff;} .empty {background:#eee;} .goal {background:#0f0;} .box {background:#f00;} .box-on-goal {background:#ff0;} .player {background:#00f;} </style> </head> <body> <h1>Box-pushing puzzle</h1> <div id="board"></div> <div id="steps">0</div> <div id="pushes">0</div> <div id="status">Not solved yet</div> <button id="restart">Restart</button> <button data-dir="up">Up</button> <button data-dir="down">Down</button> <button data-dir="left">Left</button> <button data-dir="right">Right</button> <script id="game"> const MAP = `######## ## # # ##### # +$ .# # $ * # # # ########`.trim().split('\n'); const ROWS = MAP.length, COLS = MAP[0].length; const goalMask = []; for (let y=0; y<ROWS; y++) { goalMask[y] = []; for (let x=0; x<COLS; x++) { const ch = MAP[y][x]; goalMask[y][x] = (ch === '.' || ch === '+' || ch === '*'); } } function createGame() { let player = null; let boxes = []; for (let y=0; y<ROWS; y++) { for (let x=0; x<COLS; x++) { const ch = MAP[y][x]; if (ch === '+' || ch === '@') { player = [x,y]; } else if (ch === '$') { boxes.push([x,y]); } else if (ch === '*') { boxes.push([x,y]); } } } boxes.sort((a,b)=>a[1]-b[1]||a[0]-b[0]); let pushes = 0, steps = 0, solved = false; const state = () => ({player, boxes, pushes, steps, solved}); const walk = dir => { if (solved) return; const dirs = {up:{0,-1},down:{0,1},left:-1,right:1}; const [dx,dy] = dirs[dir]; const [px,py] = player; const nx = px+dx, ny = py+dy; if (MAP[ny][nx] === '#') return; const boxIdx = boxes.findIndex(b=>b[0]===nx && b[1]===ny); if (boxIdx !== -1) { const bx = nx+dx, by = ny+dy; if (MAP[by][bx] === '#') return; if (boxes.some((b,i)=>i!==boxIdx && b[0]===bx && b[1]===by)) return; boxes[boxIdx] = [bx,by]; pushes++; } player = [nx,ny]; steps++; solved = boxes.every(b => { const cell = MAP[b[1]][b[0]]; return cell === '.' || cell === '*' || cell === '+'; }); }; return {walk, state}; } </script> <script> const game = createGame(); const board = document.getElementById('board'); const stepsEl = document.getElementById('steps'); const pushesEl = document.getElementById('pushes'); const statusEl = document.getElementById('status'); const restartBtn = document.getElementById('restart'); function draw(state) { board.innerHTML = ''; for (let y=0; y<ROWS; y++) { for (let x=0; x<COLS; x++) { const isGoal = goalMask[y][x]; const cell = document.createElement('div'); cell.setAttribute('role','img'); let char = ''; let cls = ''; if (state.player[0]===x && state.player[1]===y) { char = '+'; cls = 'player'; } else { const box = state.boxes.find(b=>b[0]===x && b[1]===y); if (box) { if (isGoal) { char = '*'; cls = 'box-on-goal'; } else { char = '$'; cls = 'box'; } } else { if (isGoal) { char = '.'; cls = 'goal'; } else { char = MAP[y][x]; cls = (MAP[y][x] === '#') ? 'wall' : 'empty'; } } } cell.className = cls; cell.textContent = char; let label = ''; if (cls === 'wall') label = 'wall'; else if (cls === 'empty') label = 'empty floor'; else if (cls === 'goal') label = 'goal'; else if (cls === 'box') label = 'box'; else if (cls === 'box-on-goal') label = 'box on goal'; else if (cls === 'player') label = 'player'; else label = 'empty'; cell.setAttribute('aria-label', label); board.appendChild(cell); } } } function scheduleUpdate() { setTimeout(() => { const s = game.state(); stepsEl.textContent = s.steps; pushesEl.textContent = s.pushes; if (s.solved) statusEl.textContent = `Solved in ${s.steps} steps with ${s.pushes} pushes`; else statusEl.textContent = 'Not solved yet'; draw(s); }, 100); } document.addEventListener('keydown', e => { if (e.key === 'ArrowUp') { game.walk('up'); scheduleUpdate(); } else if (e.key === 'ArrowDown') { game.walk('down'); scheduleUpdate(); } else if (e.key === 'ArrowLeft') { game.walk('left'); scheduleUpdate(); } else if (e.key === 'ArrowRight') { game.walk('right'); scheduleUpdate(); } }); document.querySelectorAll('button[data-dir]').forEach(btn => { btn.addEventListener('click', () => { const dir = btn.dataset.dir; game.walk(dir); scheduleUpdate(); }); }); restartBtn.addEventListener('click', () => { game = createGame(); scheduleUpdate(); }); </script> </body> </html>MinesweeperFailed
24,828 tokens: 1,438 read, 23,390 written · 5 min 22 s · 72.6 tok/s
Build Minesweeper as one web page: a 9 by 9 board with 10 mines, in the layout below, with the board drawn on the page. In <script id="game">, define createGame() returning an object with press(move) and state(). The site plays the game more than once, calling createGame() again each time, so every game starts from the layout. move is an array [kind, row, col]: kind is "open" or "flag", row is 0 (top) to 8 (bottom), col is 0 (left) to 8 (right). state() returns {cells, status, mines_left}: cells is 9 strings of 9 characters, one per row from the top. A character is "#" for a hidden cell, "F" for a flagged cell, "." for an opened cell with no mines around it, "1" to "8" for an opened cell with that many mines among the 8 cells around it, and "*" for a mine after a loss. status is "playing", "won" or "lost". mines_left is 10 minus the number of flagged cells, and can be negative. The mines, row by row from the top. In this layout * is a mine and . is a safe cell. row 0 *.......* row 1 ......... row 2 ........* row 3 ......... row 4 ..*...... row 5 ....***.. row 6 ......... row 7 ..***.... row 8 ......... The rules, exactly: 1. The game starts with every cell hidden, no flags, and status "playing". 2. press(["open", r, c]) on a hidden cell opens it. If it is a mine, status becomes "lost" and every mine shows "*", flagged or not. Otherwise the cell shows its number, or "." when no mine is among the cells around it. 3. An opened cell with no mines around it also opens each hidden, unflagged cell around it (8 directions). Each of those with no mines around it opens its own hidden, unflagged neighbours the same way, repeatedly, until nothing more opens. A flagged cell is never opened this way, and nothing spreads from it. A numbered cell opens, but nothing spreads from it. 4. press(["open", r, c]) on a flagged cell or an opened cell does nothing. 5. press(["flag", r, c]) on a hidden cell flags it. On a flagged cell it removes the flag, and the cell is hidden again. On an opened cell it does nothing. 6. status becomes "won" when every cell without a mine is opened, however the last cell is opened. A flag does not count: a flagged cell without a mine must be unflagged and opened. After a win every mine shows "F" and counts as flagged, whether or not the player flagged it, so mines_left is 0. 7. Once status is "won" or "lost", press does nothing. After a loss a flag still counts in mines_left, even on a mine that shows "*", and a flag on a safe cell still shows "F". The page: a title, a short paragraph of rules, then one white panel holding a status line, a Flag mode button and the board, on a warm off-white page. The type is the system sans-serif (font-family: system-ui, sans-serif); load no font. Give these parts these names, so the site can read them: - an element with role="status": it shows "Mines left" and mines_left as a number, with a minus sign when it is below zero, then the status word, "Playing", "Won" (green) or "Lost" (red); - a button with id="flag-mode": it starts with the text "Flag mode: off" and aria-pressed="false". When it is on, its text is "Flag mode: on", aria-pressed="true", and it is drawn in the pink accent; - the board, which is either 81 cell buttons, each with data-row (0 at the top to 8) and data-col (0 at the left to 8), or one canvas that draws all of it, with the id board: 324 pixels across and down (set its width and height attributes), nine squares of 36 pixels each way, row 0 at the top and column 0 at the left. On a canvas, a click or a right-click acts on the square under the pointer: find the square from the event's offsetX and offsetY, each scaled by the canvas's width over its clientWidth (or its height over its clientHeight), since a phone may draw the canvas smaller. A click on a cell calls press(["open", row, col]) for that cell, unless Flag mode is on: then it calls press(["flag", row, col]). A right-click on a cell (the contextmenu event) calls press(["flag", row, col]) and prevents the browser's own menu. Draw the board from state() after every press: a hidden or empty cell shows no text, a numbered cell shows its number, and a flag or a mine shows a mark with text in it (a symbol, or a word hidden from sight). On a canvas, clear the whole canvas and draw it again after every press, the cells in reading order (row 0 first, columns left to right): a numbered cell as its number in text, a flag or a mine as one short mark in text (F, *, or another plain symbol), and a hidden or empty cell as nothing; the canvas draws nothing else. Flags and mines are simple marks, not emoji. The page fits a phone with no sideways scrolling. A reload of the page starts a new game: every cell is hidden, no flag is set, Flag mode is off and the status reads "Playing", so nothing from the last load is kept. The keyboard is welcome but not checked: Tab moves between cells, Enter or Space opens one, and F flags it. The page runs its own code only: no eval, no Function(), no timer given as text, and no network request (fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon or importScripts). It loads nothing from another site. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Minesweeper</title> <style> body { font-family: system-ui, sans-serif; background-color: #f5f0e6; margin: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; } h1 { margin-bottom: 10px; } p.rules { margin-bottom: 20px; max-width: 600px; text-align: center; } #status { margin-bottom: 10px; font-weight: bold; } #flag-mode { margin-bottom: 10px; padding: 8px 12px; font-size: 1rem; cursor: pointer; } #board { width: 324px; height: 324px; border: 2px solid #333; background-color: #fff; } </style> </head> <body> <h1>Minesweeper</h1> <p class="rules"> Click or press Enter/Space to open a cell. In Flag mode, click or press F to toggle a flag. Right‑click (or contextmenu) also toggles a flag. The game starts with all cells hidden, 9 mines (as per layout), 10 mines left, and status “Playing”. </p> <div role="status" id="status">Mines left: 9 Playing</div> <button id="flag-mode" aria-pressed="false">Flag mode: off</button> <canvas id="board" width="324" height="324"></canvas> <script id="game"> function createGame() { const rows = [ "*.......*", ".........", "........*", ".........", "..*......", "....**...", ".........", "..***....", "........." ]; const n = 9; // build mine grid const isMineGrid = Array.from({length:n}, () => Array(n).fill(false)); for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (rows[r][c] === '*') { isMineGrid[r][c] = true; } } } // compute adjacent counts for non-mine cells const countGrid = Array.from({length:n}, () => Array(n).fill(0)); for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (!isMineGrid[r][c]) { for (let dr = -1; dr <= 1; dr++) { for (let dc = -1; dc <= 1; dc++) { if (dr === 0 && dc === 0) continue; const nr = r + dr, nc = c + dc; if (nr >= 0 && nr < n && nc >= 0 && nc < n && isMineGrid[nr][nc]) { countGrid[r][c]++; } } } } } } // cell objects const cells = []; for (let r = 0; r < n; r++) { cells[r] = []; for (let c = 0; c < n; c++) { cells[r][c] = { isMine: isMineGrid[r][c], revealed: false, flagged: false, count: countGrid[r][c] }; } } let status = "playing"; let mines_left = isMineGrid.flat().filter(v => v).length; // total mines // helper to count flagged cells function countFlagged() { let cnt = 0; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (cells[r][c].flagged) cnt++; } } return cnt; } // recursive open function openCell(r, c) { const cell = cells[r][c]; if (cell.revealed || cell.flagged) return; cell.revealed = true; if (cell.count === 0) { for (let dr = -1; dr <= 1; dr++) { for (let dc = -1; dc <= 1; dc++) { if (dr === 0 && dc === 0) continue; const nr = r + dr, nc = c + dc; if (nr >= 0 && nr < n && nc >= 0 && nc < n) { const neighbor = cells[nr][nc]; if (!neighbor.revealed && !neighbor.flagged) { openCell(nr, nc); } } } } } } // press handler function press(move) { if (status !== "playing") return; const [kind, r, c] = move; if (kind === "flag") { if (r < 0 || r >= n || c < 0 || c >= n) return; const cell = cells[r][c]; if (cell.revealed) return; if (cell.flagged) { cell.flagged = false; } else { cell.flagged = true; } } else if (kind === "open") { if (r < 0 || r >= n || c < 0 || c >= n) return; const cell = cells[r][c]; if (cell.flagged || cell.revealed) return; if (cell.isMine) { status = "lost"; // reveal all mines for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (cells[i][j].isMine) { cells[i][j].revealed = true; } } } // mines_left unchanged return; } else { openCell(r, c); } } // check win condition let win = true; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { const cell = cells[r][c]; if (cell.isMine) { if (status === "won") { if (!cell.flagged) win = false; } else { win = false; } } else { if (!cell.revealed) { win = false; } if (cell.flagged) { win = false; } } } } if (win) { status = "won"; // force flag all mines for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (cells[r][c].isMine) { cells[r][c].flagged = true; } } } mines_left = 0; } // update mines_left mines_left = isMineGrid.flat().filter(v => v).length - countFlagged(); } // state getter function state() { const rowsStr = []; for (let r = 0; r < n; r++) { let row = ''; for (let c = 0; c < n; c++) { const cell = cells[r][c]; let ch = ''; if (cell.flagged) { ch = 'F'; } else if (cell.revealed) { if (cell.isMine) { if (status === 'lost') { ch = '*'; } } else { if (cell.count === 0) { ch = '.'; } else { ch = cell.count.toString(); } } } else { ch = '#'; } row += ch; } rowsStr.push(row); } return { cells: rowsStr, status: status, mines_left: mines_left }; } return { press, state }; } </script> <script> /* UI wiring */ const game = createGame(); const statusEl = document.getElementById('status'); const flagBtn = document.getElementById('flag-mode'); const canvas = document.getElementById('board'); let flagMode = false; let selectedRow = -1, selectedCol = -1; // draw board from current game state function drawBoard() { const state = game.state(); const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); const n = 9; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { const cell = state.cells[r][c]; const x = c * 36; const y = r * 36; let charToDraw = ''; if (cell.flagged) { charToDraw = 'F'; } else if (cell.revealed) { if (cell.isMine) { if (state.status === 'lost') { charToDraw = '*'; } } else { if (cell.count === 0) { charToDraw = '.'; } else { charToDraw = cell.count.toString(); } } } if (charToDraw) { ctx.fillStyle = 'black'; ctx.font = '30px system-ui, sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(charToDraw, x + 18, y + 18); } } } } // update status line function updateStatus() { const s = game.state(); const mins = s.mines_left; const statusWord = s.status; const color = (statusWord === 'Won') ? 'green' : (statusWord === 'Lost') ? 'red' : 'black'; statusEl.textContent = `Mines left: ${mins} ${statusWord}`; statusEl.style.color = color; } // flag mode button flagBtn.addEventListener('click', () => { flagMode = !flagMode; flagBtn.textContent = flagMode ? 'Flag mode: on' : 'Flag mode: off'; flagBtn.setAttribute('aria-pressed', flagMode); flagBtn.style.backgroundColor = flagMode ? '#ff69b4' : ''; flagBtn.style.color = flagMode ? 'white' : 'black'; }); // canvas click canvas.addEventListener('click', e => { const rect = canvas.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const col = Math.floor(x / 36); const row = Math.floor(y / 36); if (row >= 0 && row < 9 && col >= 0 && col < 9) { selectedRow = row; selectedCol = col; if (flagMode) { game.press(['flag', row, col]); } else { game.press(['open', row, col]); } drawBoard(); updateStatus(); } }); // canvas contextmenu (right-click) canvas.addEventListener('contextmenu', e => { e.preventDefault(); const rect = canvas.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const col = Math.floor(x / 36); const row = Math.floor(y / 36); if (row >= 0 && row < 9 && col >= 0 && col < 9) { selectedRow = row; selectedCol = col; game.press(['flag', row, col]); drawBoard(); updateStatus(); } }); // keyboard handling document.addEventListener('keydown', e => { if (selectedRow === -1) return; if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); game.press(['open', selectedRow, selectedCol]); drawBoard(); updateStatus(); } else if (e.key.toLowerCase() === 'f' && flagMode) { e.preventDefault(); game.press(['flag', selectedRow, selectedCol]); drawBoard(); updateStatus(); } }); // initial draw drawBoard(); updateStatus(); </script> </body> </html>Step sequencerFailed
22,342 tokens: 1,322 read, 21,020 written · 5 min 5 s · 68.9 tok/s
Build a web page called "Step sequencer": three rows labelled Kick, Snare and Hat, of 16 step buttons each, a Play button and a Stop button, and drums made with the Web Audio API, with no sound files. In <script id="game">, define createGame() returning an object with press(cmd) and state(). The page calls createGame() at load or on the first press. The logic keeps the pattern, whether it is playing, the playhead and the hits. The page makes the sound. Do not use eval or Function, and never run text as code: give a timer a function, not a string. The starting pattern, one row per track. Steps are numbered from 1 in the rows below: each row is 16 characters, 1 for on and 0 for off. The first character is step 1 on the page and step 0 for press(): kick 1000100010001000 snare 0000100000001100 hat 1010101010101010 The rules, exactly: 1. At the start, playing is false, playhead is 0 and hits is []. 2. press([track, step]) toggles one cell: track 0 is kick, 1 snare, 2 hat; step is 0 to 15, where 0 is the first step. Toggling changes the pattern and nothing else. 3. press('play') does nothing when playing is already true. Otherwise it sets playing to true, and hits becomes the list of track numbers (0 kick, 1 snare, 2 hat) whose cell at the playhead is 1, in ascending order ([] when there are none). So the step under the playhead sounds as play starts. 4. press('stop') sets playing to false, playhead to 0 and hits to []. 5. press('tick') does nothing unless playing is true. When it is, playhead goes on by one, and after 15 it goes back to 0. hits becomes the list of track numbers whose cell at the new playhead is 1, in ascending order ([] when there are none). 6. Any other cmd does nothing: a list that is not exactly two whole numbers (such as [0, 1, 2], [1], [] or [true, 0]), null, a number, true or false, a word other than play, stop or tick, and a track or step outside the ranges above. Track and step are whole numbers. state() returns {playing, playhead, hits, pattern}: playing is true or false; playhead is 0 to 15; hits lists the track numbers set by the last tick or by the play that started playback, in ascending order ([] at the start and after stop); pattern is three strings of 16 characters, kick first, each character 1 or 0. The page: - Each step button is a real button with the attributes data-track (0, 1 or 2) and data-step (0 to 15), and aria-pressed set to true or false to match its state. A click calls press([track, step]), and after every press, the page draws from state(). - A step that is on has the class on, and the stylesheet fills it dark; a step that is off has no class on. - Play has the id play and Stop the id stop. Play calls press('play') and starts one timer that calls press('tick') every 125 ms: 120 quarter-note beats a minute, four steps to a beat. Stop calls press('stop') and clears the timer. Each play and each tick sounds the hits that state() then reports, and nothing else sounds. - Play has the disabled attribute while playing, and Stop has it while stopped. - A status line with the id status reads "Stopped", or "Playing, step N of 16" with N the playhead plus 1. Give it a fixed height, so the grid does not move when its text changes. - A span with the id announce, set to aria-live polite, is empty until playback starts for the first time. From then on it says "Playing" when playback starts and "Stopped" when it stops, and changes at no other time. - The cells in the playhead column have the class playhead while playing, and no cell has it while stopped. - The numbers 1 to 16, as text, sit above the grid, and the playhead's number is pink. Under 720 px each step shows its number. - When the page becomes hidden, it presses Stop, so nothing sounds in a background tab. - Each track in hits plays its drum: kick is a falling sine tone, snare a short noise burst with a low body tone, hat a short high noise burst. Tones use oscillators; noise bursts use buffer sources playing a buffer of random samples: the kick is one oscillator, the snare one buffer source and one oscillator, the hat one buffer source. Hits that land together must not clip, so put a gain or a limiter before the output. Create the AudioContext inside the first click (browsers need a click before they make sound), and resume it if it is suspended. - Flat and plain: a light background, dark ink, no shadows or gradients, Play the one pink button (#b31f57), and the playhead cell outlined in pink where you are. At 1280 px the 16 steps sit in one row; under 720 px they form two bars of 8. The page never scrolls sideways. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and drives the sequencer through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Step sequencer</title> <style> body { background:#f0f0f0; margin:0; padding:10px; font-family:Arial,Helvetica,sans-serif; overflow:hidden; } #status { height:30px; font-weight:bold; margin-top:10px; } #announce { display:none; } #play, #stop { margin-right:5px; padding:8px 16px; border:none; cursor:pointer; } #play { background:#b31f57; color:#fff; } #stop { background:#555; color:#fff; } .grid-wrapper { display:flex; flex-direction:column; align-items:center; margin-top:10px; } .step-numbers { display:flex; justify-content:center; margin-bottom:5px; } .num { width:30px; text-align:center; line-height:30px; font-size:14px; } .grid { display:grid; grid-template-columns: repeat(16, 1fr); gap:2px; margin-bottom:5px; } @media (max-width:720px) { .grid { grid-template-columns: repeat(8, 1fr); } } .step { width:30px; height:30px; border:1px solid #999; background:#fff; cursor:pointer; } .step.on { background:#111; color:#fff; } .step.playhead { outline:2px solid #b31f57; } </style> </head> <body> <script id="game"> function createGame() { let pattern = [ "1000100010001000", "0000100000001100", "1010101010101010" ]; let playing = false; let playhead = 0; let hits = []; function ensureAudioContext() { if (!AudioContext && !webkitAudioContext) return; if (!audioContext) { audioContext = new AudioContext(); if (audioContext.state === "suspended") { audioContext.resume(); } } } function playHits() { ensureAudioContext(); const gain = audioContext.createGain(); gain.connect(audioContext.destination); hits.forEach(track => { const t = track; if (t === 0) { const osc = audioContext.createOscillator(); osc.type = "sine"; osc.frequency.value = 100; osc.connect(gain); osc.start(); osc.stop(audioContext.currentTime + 0.2); } else if (t === 1) { const bodyOsc = audioContext.createOscillator(); bodyOsc.type = "sawtooth"; bodyOsc.frequency.value = 110; const bodyGain = audioContext.createGain(); bodyOsc.connect(bodyGain); bodyGain.connect(gain); bodyOsc.start(); bodyOsc.stop(audioContext.currentTime + 0.1); bodyGain.gain.setValueAtTime(0.001, audioContext.currentTime); bodyGain.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.2); const bufferLength = 1024; const noiseBuffer = audioContext.createBuffer(1, bufferLength, audioContext.sampleRate); const data = noiseBuffer.getChannelData(0); for (let i = 0; i < bufferLength; i++) { data[i] = Math.random() * 2 - 1; } const noiseSource = audioContext.createBufferSource(); noiseSource.buffer = noiseBuffer; const noiseGain = audioContext.createGain(); noiseSource.connect(noiseGain); noiseGain.connect(gain); noiseSource.start(); noiseSource.stop(audioContext.currentTime + 0.05); } else if (t === 2) { const bufferLength = 512; const noiseBuffer = audioContext.createBuffer(1, bufferLength, audioContext.sampleRate); const data = noiseBuffer.getChannelData(0); for (let i = 0; i < bufferLength; i++) { data[i] = Math.random() * 2 - 1; } const noiseSource = audioContext.createBufferSource(); noiseSource.buffer = noiseBuffer; const noiseGain = audioContext.createGain(); noiseSource.connect(noiseGain); noiseGain.connect(gain); noiseSource.start(); noiseSource.stop(audioContext.currentTime + 0.03); } }); } function press(cmd) { if (Array.isArray(cmd)) { if (cmd.length === 2) { const [track, step] = cmd; if (typeof track === "number" && typeof step === "number" && track >= 0 && track <= 2 && step >= 0 && step <= 15) { const idx = track; const current = pattern[idx][step]; pattern[idx] = current === "1" ? "0" : "1"; } } } else if (cmd === "play") { if (!playing) { playing = true; hits = []; for (let t = 0; t < 3; t++) { if (pattern[t][playhead] === "1") hits.push(t); } hits.sort((a,b)=>a-b); playHits(); } } else if (cmd === "stop") { if (playing) { playing = false; hits = []; playhead = 0; } } else if (cmd === "tick") { if (playing) { playhead = (playhead + 1) % 16; hits = []; for (let t = 0; t < 3; t++) { if (pattern[t][playhead] === "1") hits.push(t); } hits.sort((a,b)=>a-b); playHits(); } } } function state() { return { playing, playhead, hits, pattern }; } return { press, state }; } </script> <script> document.addEventListener('DOMContentLoaded', () => { const game = createGame(); // status line const status = document.createElement('div'); status.id = 'status'; status.style.height = '30px'; status.style.fontWeight = 'bold'; status.textContent = 'Stopped'; document.body.appendChild(status); // announce span const announce = document.createElement('span'); announce.id = 'announce'; announce.setAttribute('aria-live', 'polite'); document.body.appendChild(announce); // play button const playBtn = document.createElement('button'); playBtn.id = 'play'; playBtn.textContent = 'Play'; playBtn.disabled = true; document.body.appendChild(playBtn); // stop button const stopBtn = document.createElement('button'); stopBtn.id = 'stop'; stopBtn.textContent = 'Stop'; stopBtn.disabled = true; document.body.appendChild(stopBtn); // grid wrapper const gridWrapper = document.createElement('div'); gridWrapper.className = 'grid-wrapper'; document.body.appendChild(gridWrapper); // step numbers const stepNumbers = document.createElement('div'); stepNumbers.className = 'step-numbers'; for (let i = 1; i <= 16; i++) { const span = document.createElement('span'); span.className = 'num'; span.textContent = i; stepNumbers.appendChild(span); } gridWrapper.appendChild(stepNumbers); // create rows for each track const tracks = [0,1,2]; tracks.forEach(track => { const row = document.createElement('div'); row.className = 'grid'; row.dataset.track = track; for (let step = 0; step < 16; step++) { const btn = document.createElement('button'); btn.type = 'button'; btn.className = 'step'; btn.dataset.track = track; btn.dataset.step = step; const pattern = game.state().pattern[track]; const isOn = pattern[step] === '1'; btn.setAttribute('aria-pressed', isOn); if (isOn) btn.classList.add('on'); btn.addEventListener('click', () => { game.press([track, step]); drawUI(); }); row.appendChild(btn); } gridWrapper.appendChild(row); }); let firstPlay = true; let tickInterval = null; function drawUI() { const state = game.state(); const { playing, playhead, hits, pattern } = state; // update button states const rows = gridWrapper.querySelectorAll('.grid'); rows.forEach((row, trackIdx) => { const track = parseInt(row.dataset.track); const patternStr = pattern[track]; const buttons = row.querySelectorAll('button'); buttons.forEach((btn, step) => { const isOn = patternStr[step] === '1'; btn.setAttribute('aria-pressed', isOn); if (isOn) btn.classList.add('on'); else btn.classList.remove('on'); if (playing && step === playhead) { btn.classList.add('playhead'); } else { btn.classList.remove('playhead'); } }); }); // play/stop button disabled playBtn.disabled = playing; stopBtn.disabled = !playing; // status text if (playing) { status.textContent = `Playing, step ${playhead + 1} of 16`; if (firstPlay) { announce.textContent = 'Playing'; firstPlay = false; } } else { status.textContent = 'Stopped'; announce.textContent = 'Stopped'; } } function startTick() { if (tickInterval) return; tickInterval = setInterval(() => { game.press('tick'); drawUI(); }, 125); } function stopTick() { if (tickInterval) { clearInterval(tickInterval); tickInterval = null; } } playBtn.addEventListener('click', () => { game.press('play'); drawUI(); startTick(); }); stopBtn.addEventListener('click', () => { game.press('stop'); drawUI(); stopTick(); }); document.addEventListener('visibilitychange', () => { if (document.hidden) { game.press('stop'); drawUI(); stopTick(); } }); drawUI(); }); </script> </body> </html>Grow a branching plantFailed
13,860 tokens: 1,249 read, 12,611 written · 3 min 8 s · 67 tok/s
Build a plant that grows by a rewrite rule (an L-system) as one web page: a heading, a canvas that draws the plant, a Grow button and a Reset button. In <script id="game">, define createGame() returning an object with grow() and state(). grow() takes no argument. state() returns {generation, text, segments}: generation is a number, text is a string, and segments is a list with one [x1, y1, x2, y2] entry for each F in text, in the order the Fs appear in text. [x1, y1] is the cell a segment starts from and [x2, y2] the cell it ends on. The rules, exactly: 1. A pen starts at [0, 0] facing north, which is heading 6. Headings are numbered 0 to 7 clockwise, each one a step [dx, dy] with y growing downward: 0 [1, 0] east, 1 [1, 1] south-east, 2 [0, 1] south, 3 [-1, 1] south-west, 4 [-1, 0] west, 5 [-1, -1] north-west, 6 [0, -1] north, 7 [1, -1] north-east. 2. The text starts as F, at generation 0. The pen reads the text from left to right. F moves the pen one step along its heading and adds the segment [x1, y1, x2, y2] for that step. + adds 1 to the heading and - subtracts 1, both modulo 8. [ saves the pen's position and heading. ] restores the last saved position and heading and forgets them. Any other symbol does nothing. 3. grow() rewrites the text in one pass: every F becomes F[[++F]+F[--F]]F, and every other symbol stays as it is. The Fs that the rule adds are not rewritten in that pass. Then generation goes up by 1. 4. segments is what the pen draws over the new text, starting again at [0, 0] facing north, as in rule 1. 5. At the start, generation is 0, text is "F" and segments is [[0, 0, 0, -1]]. 6. grow() at generation 4 changes nothing: generation, text and segments stay as they are. The site calls grow() five times in a row, and reads state() before the first call and after each call, so every state must match these rules. The fifth call is made at generation 4. Keep the rule in the game script as one string, written exactly as rule 3 gives it: the site also runs the script with another rule in its place, and its states must follow that rule. The page: a heading (an <h1>) reading exactly "Grow a branching plant". Below it, one canvas draws each segment as a line from its start point to its end point, with the context's own moveTo, lineTo and stroke (not Path2D). The canvas draws nothing else: no other shapes, no text and no images. The drawing has the shape the segments give, with north up on the canvas: one scale on both axes, fitted to the canvas and centred. Each drawing starts by clearing the whole canvas (clearRect over all of it, or setting the canvas's width), so only the new plant is on it. Each press of Grow draws the whole plant again, at once, with one lineTo for each segment: no animation frames and no delays. The plant is drawn when the page loads, and Reset draws the stem again within a tenth of a second. Grow is a <button id="grow"> reading exactly "Grow". A press calls grow(), then draws and shows the new state, and Grow is disabled at generation 4. Reset is a <button id="reset"> reading exactly "Reset". A press calls createGame() for a new plant, draws it, and enables Grow again. Wire both with addEventListener('click', ...). A status line, an element with role="status", reads "Generation g of 4, n segments", where g is the generation and n the number of segments (the word is "segment" when n is 1), and it changes after each press. Look: plain and tidy, like a small app. A light, warm off-white page, the canvas in a white card with a thin border, the plant in dark ink, Grow as the main button and Reset as an outlined button under the card. The page must work at 390 px and at 1280 px wide with no sideways scrolling. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not use document, window, localStorage, sessionStorage or any timer, because the site runs that script on its own and plays the game through createGame(). The script is at most 20,000 characters. Wire the page in another <script>. Neither script may use eval or Function, reach Function through a constructor, or give a timer text to run; and neither may read window, self, globalThis, top, parent, frames or this with square brackets. A constructor() method in a class is fine, and so is a constructor key in an object; reading a constructor property, as x.constructor or x['constructor'], is not. A timer is given a function: one written in the call, or one the page declares by name. Square brackets take a number or a name, never quoted text, and window is used only as window.name.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Grow a branching plant</title> <style> body { background:#f5f0e6; font-family:sans-serif; margin:0; display:flex; flex-direction:column; align-items:center; } .card { background:#fff; border:1px solid #ccc; padding:10px; margin:20px; max-width:100%; box-sizing:border-box; } h1 { text-align:center; margin:0; } canvas { display:block; width:100%; height:auto; background:#fff; } button#grow { padding:8px 16px; font-size:1rem; } button#reset { padding:8px 16px; font-size:1rem; border:1px solid #ccc; background:transparent; } #status { margin-top:10px; text-align:center; font-size:0.9rem; } </style> </head> <body> <h1>Grow a branching plant</h1> <div class="card"> <canvas id="canvas"></canvas> <div id="status" role="status"></div> </div> <button id="grow">Grow</button> <button id="reset">Reset</button> <script id="game"> function createGame() { let generation = 0; let text = "F"; let segments = []; const dirs = [ [1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1] ]; function computeSegments() { let x = 0, y = 0; let heading = 6; // north const stack = []; const segs = []; for (let i = 0; i < text.length; i++) { let c = text[i]; if (c === 'F') { let dx = dirs[heading][0]; let dy = dirs[heading][1]; segs.push([x, y, x + dx, y + dy]); x += dx; y += dy; } else if (c === '+') { heading = (heading + 1) % 8; } else if (c === '-') { heading = (heading + 7) % 8; } else if (c === '[') { stack.push({x, y, heading}); } else if (c === ']') { let saved = stack.pop(); x = saved.x; y = saved.y; heading = saved.heading; } } return segs; } segments = computeSegments(); return { grow() { if (generation === 4) { return; } let newText = ''; for (let i = 0; i < text.length; i++) { let c = text[i]; if (c === 'F') { newText += "F[[++F]+F[--F]]F"; } else { newText += c; } } text = newText; generation++; segments = computeSegments(); }, state() { return {generation, text, segments}; } }; } </script> <script> const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const status = document.querySelector('[role="status"]'); const growBtn = document.getElementById('grow'); const resetBtn = document.getElementById('reset'); function resizeCanvas() { const rect = canvas.parentElement.getBoundingClientRect(); canvas.width = Math.round(rect.width); canvas.height = Math.round(rect.height); } function drawPlant(game) { ctx.clearRect(0, 0, canvas.width, canvas.height); const segs = game.state().segments; ctx.strokeStyle = 'black'; segs.forEach(s => { ctx.beginPath(); ctx.moveTo(s[0], s[1]); ctx.lineTo(s[2], s[3]); ctx.stroke(); }); } function updateStatus(game) { const {generation, segments} = game.state(); const n = segments.length; const word = n === 1 ? 'segment' : 'segments'; status.textContent = `Generation ${generation} of 4, ${n} ${word}`; } function initGame() { const game = createGame(); drawPlant(game); updateStatus(game); growBtn.disabled = false; growBtn.addEventListener('click', () => { game.grow(); drawPlant(game); updateStatus(game); growBtn.disabled = (game.state().generation >= 4); }); resetBtn.addEventListener('click', () => { const newGame = createGame(); drawPlant(newGame); updateStatus(newGame); growBtn.disabled = false; }); } window.addEventListener('load', () => { resizeCanvas(); window.addEventListener('resize', resizeCanvas); initGame(); }); </script> </body> </html>Falling sandFailed
13,342 tokens: 1,142 read, 12,200 written · 2 min 43 s · 74.9 tok/s
Build a page called Falling sand: a 40 by 30 board drawn on a canvas. Sand falls one frame at a time and slides off the edges of piles. Pressing or dragging on the board pours sand, Play runs the frames, and Step runs one. In <script id="game">, define createGame(). It returns an object with play(move) and state(). move is "step" (run one frame) or [x, y] (pour one grain of sand into column x, row y). state() returns {frame, cells}: frame is the number of frames run so far (a pour is not a frame), and cells is 30 rows of 40 numbers, top row first: 0 is empty, 1 is sand, 2 is wall. Column x runs 0 to 39, left to right; row y runs 0 to 29, top to bottom. The start, exactly (both ends of each run are included): 1. frame is 0. Row 29 is all wall. 2. Walls: row 16, columns 10 to 16; row 24, columns 7 to 15; column 31, rows 22 to 26. 3. Sand: column 25, row 1; row 2, columns 22 to 28; row 3, columns 21 to 29; row 4, columns 20 to 30; row 5, columns 21 to 29; row 6, columns 22 to 28; column 25, row 7. 4. Every other cell is empty. The rules, exactly: 1. A pour [x, y] puts one grain in that cell if it is empty; a cell holding sand or wall, or outside the grid, is not empty, so the pour does nothing. 2. A step runs one frame, using frame as it is before the step, then frame goes up by 1. A frame scans the rows from row 28 up to row 0. Within a row it scans the columns from left to right when frame is even, and from right to left when frame is odd. 3. Each sand cell the scan reaches moves at most once: to (x, y+1) if that cell is empty; otherwise to (x-1, y+1) if that is empty; otherwise to (x+1, y+1) if that is empty; otherwise it stays. Anything outside the grid counts as wall. 4. Each check reads the cells as they are at that moment: a grain that has moved leaves its cell empty, and a cell an earlier grain filled in this frame is not empty. The site plays a list of moves through play() and checks state() after each one. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>. Do not run a string as code: no eval, no Function (not even as a function's constructor property), no timer given a string, no javascript: address, and no script element made from text. Network requests are refused, and the game script is at most 20,000 characters. The page: a canvas with the id board and the width and height attributes 640 and 480. The board may be shown at any size and place on the page: a press or drag finds its cell from where the board is on screen not from its 640 by 480 pixels. A press on the board pours one grain into the cell under the pointer. A drag pours into every cell on the straight line from the cell the pointer left to the cell it reached, both ends included (Bresenham's line algorithm). Buttons with the ids play, step and reset. play runs one frame about every 50 ms, and its label reads Pause while it runs; pressing it again pauses, and the label reads Play. step runs one frame. reset calls createGame() again, back to the start, and stops Play if it is running. After each pour, after each frame that Play or Step runs, and after Reset, the board is cleared or filled once, then each grain of sand is drawn with fillRect in its own cell; empty cells are not drawn one by one. One line under the board, with the id status, reads "Frame N, M grains of sand" ("1 grain of sand" for one), N is the frame and M the grains. Not checked, but wanted: keyboard pouring (arrow keys move a pour cursor when the board has focus; Space or Enter pours at it); a live region with the id say that announces Play, Pause, Step and Reset; reduced motion (prefers-reduced-motion: reduce): a press of Play runs one frame; off screen, Play pauses for real (no frame runs, the label reads Play) and resumes on return only if it was playing, and a press of Play then does nothing, while Step still runs one frame.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Falling sand</title> <style> body {font-family:sans-serif; text-align:center; margin-top:20px;} #board {border:1px solid #000; touch-action:none;} #status {margin-top:10px; font-weight:bold;} button {margin:5px; padding:5px 10px;} #say {position:absolute; left:-9999px; top:-9999px;} </style> </head> <body> <canvas id="board" width="640" height="480"></canvas> <div id="status">Frame 0, 0 grains of sand</div> <button id="play">Play</button> <button id="step">Step</button> <button id="reset">Reset</button> <div id="say" aria-live="polite"></div> <script id="game"> function createGame() { let frame = 0; let cells = Array.from({length:30}, () => Array(40).fill(0)); // walls for (let x = 10; x <= 16; x++) cells[16][x] = 2; for (let x = 7; x <= 15; x++) cells[24][x] = 2; for (let y = 22; y <= 26; y++) cells[y][31] = 2; // row 29 all wall for (let x = 0; x < 40; x++) cells[29][x] = 2; // sand initial positions cells[1][25] = 1; for (let x = 22; x <= 28; x++) cells[2][x] = 1; for (let x = 21; x <= 29; x++) cells[3][x] = 1; for (let x = 20; x <= 30; x++) cells[4][x] = 1; for (let x = 21; x <= 29; x++) cells[5][x] = 1; for (let x = 22; x <= 28; x++) cells[6][x] = 1; cells[7][25] = 1; function stepFrame() { for (let y = 28; y >= 0; y--) { const even = (frame % 2 === 0); const cols = even ? Array.from({length:40}, (_,i)=>i) : Array.from({length:40}, (_,i)=>39-i); for (let x of cols) { if (cells[y][x] !== 1) continue; const ny = y + 1; if (ny < 30 && cells[ny][x] === 0) { cells[ny][x] = 1; cells[y][x] = 0; continue; } if (ny < 30 && x-1 >= 0 && cells[ny][x-1] === 0) { cells[ny][x-1] = 1; cells[y][x] = 0; continue; } if (ny < 30 && x+1 < 40 && cells[ny][x+1] === 0) { cells[ny][x+1] = 1; cells[y][x] = 0; continue; } } } frame++; } function play(move) { if (move === "step") { stepFrame(); } else if (Array.isArray(move) && move.length === 2) { const [x, y] = move; if (x >= 0 && x < 40 && y >= 0 && y < 30 && cells[y][x] === 0) { cells[y][x] = 1; } } } function state() { return { frame, cells: cells.map(row => row.slice()) }; } return {play, state}; } </script> <script> const board = document.getElementById('board'); const playBtn = document.getElementById('play'); const stepBtn = document.getElementById('step'); const resetBtn = document.getElementById('reset'); const status = document.getElementById('status'); const say = document.getElementById('say'); let game = createGame(); let isPlaying = false; let intervalId = null; let wasPlayingBeforeHidden = false; function getCellFromEvent(clientX, clientY) { const rect = board.getBoundingClientRect(); const x = Math.floor((clientX - rect.left) / 16); const y = Math.floor((clientY - rect.top) / 16); return [x, y]; } // Bresenham line algorithm (inclusive) function bresenham(x0, y0, x1, y1) { const points = []; let dx = Math.abs(x1 - x0); let dy = Math.abs(y1 - y0); const sx = x0 < x1 ? 1 : -1; const sy = y0 < y1 ? 1 : -1; let err = dx - dy; while (true) { points.push([x0, y0]); if (x0 === x1 && y0 === y1) break; const e2 = 2 * err; if (e2 > -dy) { err -= dy; x0 += sx; } if (e2 < dx) { err += dx; y0 += sy; } } return points; } // draw current board function updateBoard() { const ctx = board.getContext('2d'); ctx.clearRect(0, 0, board.width, board.height); const cells = game.state().cells; const size = 16; // cell size for (let y = 0; y < 30; y++) { for (let x = 0; x < 40; x++) { const v = cells[y][x]; if (v === 1) { ctx.fillStyle = '#C19A6B'; ctx.fillRect(x * size, y * size, size, size); } else if (v === 2) { ctx.fillStyle = '#555'; ctx.fillRect(x * size, y * size, size, size); } } } } // update status text function updateStatus() { const s = game.state(); const frame = s.frame; const cells = s.cells; let sandCount = 0; for (let row of cells) { for (let v of row) if (v === 1) sandCount++; } const txt = sandCount === 1 ? "1 grain of sand" : `${sandCount} grains of sand`; status.textContent = `Frame ${frame}, ${txt}`; } // start / stop playing function startPlaying() { if (isPlaying) return; if (document.hidden) return; isPlaying = true; playBtn.textContent = "Pause"; intervalId = setInterval(() => { game.play("step"); updateBoard(); updateStatus(); say.textContent = "Step"; }, 50); } function stopPlaying() { if (!isPlaying) return; isPlaying = false; playBtn.textContent = "Play"; clearInterval(intervalId); intervalId = null; } function togglePlay() { if (document.hidden) return; if (isPlaying) { stopPlaying(); say.textContent = "Pause"; } else { startPlaying(); say.textContent = "Play"; } } playBtn.addEventListener('click', togglePlay); stepBtn.addEventListener('click', () => { game.play("step"); updateBoard(); updateStatus(); say.textContent = "Step"; }); resetBtn.addEventListener('click', () => { game = createGame(); stopPlaying(); say.textContent = "Reset"; updateBoard(); updateStatus(); }); // optional keyboard pouring let cursorX = 0, cursorY = 0; board.addEventListener('keydown', e => { if (e.key === "ArrowUp") { e.preventDefault(); cursorY = Math.max(0, cursorY - 1); } else if (e.key === "ArrowDown") { e.preventDefault(); cursorY = Math.min(29, cursorY + 1); } else if (e.key === "ArrowLeft") { e.preventDefault(); cursorX = Math.max(0, cursorX - 1); } else if (e.key === "ArrowRight") { e.preventDefault(); cursorX = Math.min(39, cursorX + 1); } else if (e.key === " " || e.key === "Enter") { e.preventDefault(); game.play([cursorX, cursorY]); updateBoard(); updateStatus(); say.textContent = "Pour"; } }); board.focus(); // give canvas focus // mouse handling let dragStart = null; board.addEventListener('mousedown', e => { const [x, y] = getCellFromEvent(e.clientX, e.clientY); game.play([x, y]); // pour at start cell updateBoard(); updateStatus(); say.textContent = "Pour"; dragStart = [x, y]; }); board.addEventListener('mousemove', e => { if (!dragStart) return; const [x2, y2] = getCellFromEvent(e.clientX, e.clientY); const linePoints = bresenham(dragStart[0], dragStart[1], x2, y2); for (const [cx, cy] of linePoints) { game.play([cx, cy]); } updateBoard(); updateStatus(); }); board.addEventListener('mouseup', () => { dragStart = null; }); // visibility change handling for Play pause function updatePlayState() { if (document.hidden) { if (isPlaying) { stopPlaying(); wasPlayingBeforeHidden = true; say.textContent = "Pause"; } } else { if (wasPlayingBeforeHidden) { startPlaying(); wasPlayingBeforeHidden = false; say.textContent = "Play"; } } } document.addEventListener('visibilitychange', updatePlayState); // initial update updateBoard(); updateStatus(); say.textContent = "Ready"; </script> </body> </html>Focus timerFailed
18,352 tokens: 1,110 read, 17,242 written · 3 min 42 s · 77.7 tok/s
Build a focus timer as one web page. Work periods alternate with breaks, and after every few finished work periods the break is long. The page shows the name of the period, the time left, an SVG ring that empties as the time runs down, and how many work periods are done. In <script id="game">, define createGame(). It returns an object with two methods, tick(cmd) and state(). The page's own timer calls tick() once a second, and its buttons call tick('start'), tick('pause'), tick('skip') and tick('reset'). Those four exact lowercase words are commands: they change the timer and pass no time. Any other value passes one second, and only while the timer is running: no argument, null, undefined, a number, true, false, an empty text, any other text such as 'Start' or 'tick', or an object. state() returns {phase, left, running, done}: phase is 'work', 'short' or 'long'; left is the whole number of seconds left in this period; running is true or false; done is a number. The script in <script id="game"> is at most 20,000 characters. This run's lengths: work 1200 seconds (20 minutes), short break 180 seconds (3 minutes), long break 600 seconds (10 minutes). A long break follows every 3rd finished work period. The rules, exactly: 1. The timer starts in work, with left 1200, running false and done 0. 2. 'start' sets running to true, and 'pause' sets it to false. Neither changes anything else. 3. While running, each passed second lowers left by 1. While paused, passed seconds change nothing. 4. When left reaches 0, the period is over at once, so state() never shows 0. The next period starts with its full length and paused (running false). Seconds passed after that change nothing until 'start'. 5. A work period that ends this way adds 1 to done. Then a long break comes when done is a multiple of 3, otherwise a short break. 6. 'skip' ends the current period at once, whatever left is, and the next period starts paused. A skipped work period does not add to done, and the break after it is a short break whatever done is. A skipped break is followed by work. 7. After any break comes work. A break never adds to done. 8. 'reset' sets left back to the full length of the current period and sets running to false. It does not change the phase or done. The page: - A heading, "Focus timer". - The name of the period, alone in an element with the id phase: Focus, Short break or Long break. - The time left, as mm:ss with two digits each, alone in an element with the id time. At the start of this run's work period it reads 20:00. - An SVG ring around the time: a circle with pathLength="100" and stroke-dasharray="100". Set its stroke-dashoffset attribute to 100 times (1 minus left divided by the full length of the current period) on every redraw. The arc is full, with an offset of 0, at the start of a period, and it is empty, with an offset of 100, when the time is up. A track circle without a stroke-dashoffset may sit under it. - Four buttons in one row, with the ids start, pause, skip and reset, labelled Start, Pause, Skip and Reset. Each calls tick() with its command. Start is disabled while the timer runs, and Pause is disabled while it is paused. Skip and Reset are always enabled. Below 390 px they may wrap into two rows of two. - The count in an element with the id count, in words: "Focus periods done: 3". - The page's own timer calls tick() once a second, with no argument. After every call, the page redraws from state(). When a period ends, the page may play a short chime with the Web Audio API. - Look: a light, warm off-white page with one white card, dark ink text and muted grey for the small labels. One accent colour, used for the Start button only. Flat fills, no gradients or shadows, no outside fonts or images: use the system font. It must look tidy at 390 px and at 1280 px wide, with no sideways scrolling. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the timer's logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and drives the timer through createGame(). Do not use eval, Function or any other way of running text as code: no string given to a timer, and no script element or event-handler attribute made from text while the page runs. Put the wiring in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Focus timer</title> <style> /* Light off‑white background */ body { margin:0; padding:0; background:#f5f0e6; font-family:system-ui, sans-serif; display:flex; justify-content:center; align-items:center; min-height:100vh; } /* White card with dark text */ .card { background:#fff; padding:2rem; border-radius:8px; box-shadow:0 2px 4px rgba(0,0,0,0.1); text-align:center; max-width:300px; width:100%; } /* Heading */ h1 { margin:0 0 1rem; font-size:1.5rem; color:#333; } /* Period name, time and count */ #phase, #time, #count { margin:0.5rem 0; font-size:1.2rem; color:#222; } #phase { font-weight:600; } #time { font-size:2rem; } #count { font-size:1rem; color:#555; } /* Buttons */ .buttons { margin-top:1rem; display:flex; justify-content:center; gap:0.5rem; flex-wrap:wrap; } button { background:#ff6b6b; /* accent colour – only Start */ color:#fff; border:none; border-radius:4px; padding:0.5rem 1rem; font-size:1rem; cursor:pointer; } button:disabled { background:#aaa; cursor:not-allowed; opacity:0.6; } #start:disabled, #pause:disabled { opacity:0.6; } #skip, #reset { background:#6c757d; /* neutral colour */ } #skip:disabled, #reset:disabled { background:#aaa; } /* SVG ring */ #ring { margin-top:1rem; width:120px; height:120px; } /* Responsiveness */ @media (max-width:390px) { .card { padding:1.5rem; } #time { font-size:1.5rem; } } @media (min-width:1280px) { .card { padding:2.5rem; max-width:350px; } } </style> </head> <body> <div class="card"> <h1>Focus timer</h1> <div id="phase">Focus</div> <div id="time">20:00</div> <div class="ring-container"> <svg viewBox="0 0 100 100" style="width:120px;height:120px;position:relative;display:inline-block;"> <circle cx="50" cy="50" r="15.9" stroke="#6c757d" fill="none" stroke-width="5"/> <circle cx="50" cy="50" r="15.9" stroke="#ff6b6b" fill="none" stroke-width="5" id="ring" stroke-dasharray="100"/> </svg> </div> <div id="count">Focus periods done: 0</div> <div class="buttons"> <button id="start" disabled>Start</button> <button id="pause" disabled>Pause</button> <button id="skip">Skip</button> <button id="reset">Reset</button> </div> </div> <script id="game"> function createGame() { let phase = 'work'; let left = 1200; let running = false; let done = 0; function playChime() { if (!window.AudioContext && !window.webkitAudioContext) return; const AudioCtx = window.AudioContext || window.webkitAudioContext; const ctx = new AudioCtx(); const osc = ctx.createOscillator(); osc.type = 'sine'; osc.frequency.value = 440; const gain = ctx.createGain(); osc.connect(gain); gain.connect(ctx.destination); gain.gain.setValueAtTime(0.2, ctx.currentTime); osc.start(ctx.currentTime); osc.stop(ctx.currentTime + 0.1); } function tick(cmd) { if (cmd === 'start') { running = true; } else if (cmd === 'pause') { running = false; } else if (cmd === 'skip') { phase = 'short'; left = 180; running = false; } else if (cmd === 'reset') { if (phase === 'work') left = 1200; else if (phase === 'short') left = 180; else if (phase === 'long') left = 600; running = false; } else { if (running) { left = Math.max(0, left - 1); } } if (left <= 0) { if (phase === 'work') done += 1; if (phase === 'work') { if (done % 3 === 0) { phase = 'long'; left = 600; } else { phase = 'short'; left = 180; } } else { phase = 'work'; left = 1200; } running = false; playChime(); } } function state() { return {phase, left, running, done}; } return {tick, state}; } </script> <script> const game = createGame(); const intervalId = setInterval(() => { game.tick(); // tick with no argument (once per second) const s = game.state(); // update phase name const phaseName = (s.phase === 'work') ? 'Focus' : (s.phase === 'short') ? 'Short break' : 'Long break'; document.getElementById('phase').textContent = phaseName; // update time display (mm:ss) const minutes = Math.floor(s.left / 60); const seconds = s.left % 60; const mm = minutes.toString().padStart(2, '0'); const ss = seconds.toString().padStart(2, '0'); document.getElementById('time').textContent = `${mm}:${ss}`; // update count document.getElementById('count').textContent = `Focus periods done: ${s.done}`; // enable/disable buttons document.getElementById('start').disabled = s.running; document.getElementById('pause').disabled = !s.running; // skip and reset are always enabled // update SVG ring offset const fullLength = (s.phase === 'work') ? 1200 : (s.phase === 'short') ? 180 : 600; const offset = 100 * (1 - s.left / fullLength); const dashOffset = Math.max(0, Math.min(100, offset)); const ring = document.getElementById('ring'); ring.setAttribute('stroke-dashoffset', dashOffset); }, 1000); </script> </body> </html>
Reasons are shown for the fixed tasks. The varied tasks keep their checks private so answers cannot be fitted to them.
Think a grade is wrong? Say so in the chat.
What it built
Pages and games, as the model wrote them, each in a sandbox. Open one, then swipe or use the arrow keys.
-
Build 2048Keeps a game's rules across many moves.Failed · 18k tokens · 60.4 tok/s
-
Build SnakeRuns a game where a snake grows and the game ends on a crash.Failed · 10k tokens · 64.4 tok/s
-
Box-pushing puzzleShows whether a model can follow the push rules exactly across a whole level, counting steps and pushes as the rules say.Failed · 15k tokens · 64.3 tok/s
-
MinesweeperShows whether a model keeps the rules of a small game exact: where an empty area stops spreading, what a flag does to the count, and what a win or a loss reveals.Failed · 25k tokens · 72.6 tok/s
-
A small websiteLays out a small website with a menu and a footer.Passed · 2.3k tokens · 78.1 tok/s
-
A pricing table with a toggleSwitches every price between monthly and yearly with one button.Passed · 5k tokens · 73.4 tok/s
-
An accessible sign-up formChecks a sign-up form and labels each of its fields.Passed · 1.8k tokens · 78.9 tok/s
-
A to-do app that remembersKeeps data across a reload.Passed · 1.9k tokens · 68.6 tok/s
-
A bar chart in SVGDraws data to scale.Passed · 3.3k tokens · 63.3 tok/s
-
Step sequencerShows whether a model can keep a beat in time, step by step.Failed · 22k tokens · 68.9 tok/s
-
Grow a branching plantThis shows whether a model can apply a branching rewrite rule exactly, over four rounds of growth.Failed · 14k tokens · 67 tok/s
-
Falling sandShows whether a model can follow exact falling rules, cell by cell and frame by frame.Failed · 13k tokens · 74.9 tok/s
-
Focus timerShows whether a model keeps a focus timer exact through pauses, skips and resets.Failed · 18k tokens · 77.7 tok/s
Scored tasks
Summarizing 2 of 5
One-sentence summaryFailed
431 tokens: 111 read, 320 written · 4 s · 75.5 tok/s
Summarize this in one sentence of at most 30 words. Starting August 3, the Thornbury Public Library will open at 6:45 a.m. instead of 9:50 a.m. on weekdays. The change follows a survey in which 50% of respondents asked for earlier hours. Weekend hours stay the same. The library will hire two part-time staff to cover the extra time, paid for by a county grant.
Starting August 3, Thornbury Library opens weekdays at 6:45 a.m. (instead of 9:50 a.m.) after a 50% survey vote, hiring two part‑time staff funded by a county grant, while weekend hours remain unchanged.
Meeting notes in three bulletsFailed
1,001 tokens: 196 read, 805 written · 14 s · 56.6 tok/s
Summarize these meeting notes as exactly three bullet points, each at most 20 words. Keep only the decisions and ownership changes that matter. Output only the bullet points. Weekly sync, design team. Present: Zara, Jules, Priya, Mei. - Priya reported that the payment provider fixed the export bug; no action needed. - The launch date moves from October 13 to October 20 because the legal review is taking longer. - Mei showed the new onboarding screens. Everyone liked them. Small copy changes only. - The marketing budget of $60,000 was approved by finance on Saturday. - Zara will own end-to-end testing from now on; Jules hands over the test plan by Tuesday. - Next sync is moved to Monday at 09:15. - Coffee machine on floor 6 is broken again.
- Launch date moved to October 20 because legal review is delayed. - Finance approved $60,000 marketing budget; Zara takes ownership of end‑to‑end testing. - Jules will hand over the test plan by Tuesday; next sync set for Monday at 09:15.
Review sentiment and complaintPassed
348 tokens: 124 read, 224 written · 4 s · 60.5 tok/s
Read this product review and answer in exactly this format: Sentiment: <positive, negative or mixed> Complaint: <the main complaint in a few words> I've used this toaster every day for a month. Honestly, the settings are easy to read and it looks lovely on the counter. But the heating element that came in the box cracked after two weeks, and support took 4 days to reply. I bought a replacement heating element myself. Would I buy it again? Probably, but I'm annoyed.
Sentiment: mixed Complaint: Cracked heating element
Faithful summary of a studyFailed
477 tokens: 141 read, 336 written · 5 s · 61.5 tok/s
Summarize this in at most 50 words. Keep the key numbers. Do not add anything the text does not say. In a randomized trial, 960 adults with chronic migraine took either Soltide or a placebo for 10 weeks. Those on Soltide had 3.9 fewer headache days per month on average, compared with 0.8 fewer days for placebo. Fatigue was the most common side effect, reported by 12% of the drug group. The authors note the trial lasted only 10 weeks and call for longer studies before any recommendation is made.
In a 10‑week, 960‑person randomized trial, Soltide reduced migraine days by 3.9 per month versus 0.8 with placebo; 12% reported fatigue. Authors note the short duration and urge longer studies before recommending it.
Action items from an email threadPassed
907 tokens: 220 read, 687 written · 10 s · 71.3 tok/s
List every action item in this email thread that someone has committed to do, as lines of the form "- <owner>: <action>". Leave out offers that were declined and things that turned out not to be needed. Output only the list. From: Ines Hi all, quick recap of what's still open for the autumn summit. I'll send the revised contract to the hotel by Sunday. From: Mateo I can book the venue for the dinner if that helps? From: Ivy Thanks Mateo, but I'll book the venue myself since I already spoke to them. Also, no need to change the logo on the badges, it's fine as is. From: Oscar I'll update the budget sheet with the new hotel price tonight. From: Ines Great. Oh, and I'll email the caterer about the vegetarian options. Mateo, could you just double-check the date on the invitations? Actually never mind, I checked them this morning, they're correct.
- Ines: send revised contract to hotel by Sunday - Ivy: book the venue - Oscar: update the budget sheet with the new hotel price tonight - Ines: email the caterer about the vegetarian options
Extracting 5 of 5
Fields from an email as JSONPassed
355 tokens: 126 read, 229 written · 3 s · 71 tok/s
Extract these fields from the email as a JSON object with exactly these keys: "name" (the sender's full name), "company", "meeting_date" (YYYY-MM-DD) and "attendees" (a number). Output only the JSON. Hello! This is Ingrid Ibarra from Meridian Stationery. We'd love to visit your workshop. Could we meet on the 10th of July 2025, any time after lunch? We'll be seven people in total, including me. Best, Ingrid
{ "name": "Ingrid Ibarra", "company": "Meridian Stationery", "meeting_date": "2025-07-10", "attendees": 7 }Every email address, oncePassed
616 tokens: 155 read, 461 written · 6 s · 72.6 tok/s
List every email address written out in full in this text (like name@example.com), one per line, in the order they first appear, without duplicates. Leave out any inbox the text says is closed. Output only the addresses. Contacts for the conference: write to info@cedar-summit.com for general questions, or to program@cedar-summit.com if you are presenting. Our designer (priya.t@ink-and-oak.io) made the poster. Billing questions: billing@cedar-summit.com. Again, presenters use program@cedar-summit.com. Please don't write to kim at cedar dot com, that inbox is closed.
info@cedar-summit.com program@cedar-summit.com priya.t@ink-and-oak.io billing@cedar-summit.com
A list as CSVPassed
558 tokens: 111 read, 447 written · 6 s · 74 tok/s
Convert this shopping list to CSV with the header row item,qty,price. Write prices as plain numbers without a currency sign. Output only the CSV. Olive oil (1 l) - 23 @ $3.35 Cheddar (200 g) - 2 @ $8.00 Bread loaf - 7 @ $0.30 Peanut butter - 11 @ $7.90
item,qty,price Olive oil (1 l),23,3.35 Cheddar (200 g),2,8.00 Bread loaf,7,0.30 Peanut butter,11,7.90
The real deadlinePassed
217 tokens: 106 read, 111 written · 2 s · 61.2 tok/s
What is the final submission deadline? Answer with the date only, in YYYY-MM-DD format. The call for papers opened on 7 January 2027. Drafts were originally due September 21, but the committee extended the final submission deadline to 28 September 2027. Reviews are due by 6 September, and results will be announced on November 13, 2027.
2027-09-28
Warnings and errors from a logPassed
887 tokens: 287 read, 600 written · 8 s · 72.4 tok/s
From this log, return a JSON array with one object per WARN or ERROR line, in order, each with the keys "time" (HH:MM:SS), "level" and "message". Output only the JSON. 2025-05-22 09:13:15 INFO server started on port 8443 2025-05-22 09:17:47 WARN config key "max body" is deprecated 2025-05-22 09:22:37 INFO user lucas logged in 2025-05-22 09:23:04 ERROR database connection lost 2025-05-22 09:28:22 INFO retrying in 10s 2025-05-22 09:29:33 INFO database reconnected 2025-05-22 09:33:13 DEBUG cache hit ratio 0.83 2025-05-22 09:35:37 ERROR payment webhook returned 504
[ {"time":"09:17:47","level":"WARN","message":"config key \"max body\" is deprecated"}, {"time":"09:23:04","level":"ERROR","message":"database connection lost"}, {"time":"09:35:37","level":"ERROR","message":"payment webhook returned 504"} ]
Following instructions 4 of 5
Exactly one wordPassed
74 tokens: 26 read, 48 written · 1 s · 46.7 tok/s
Reply with exactly the word Done and nothing else.
Done
Three lowercase linesPassed
665 tokens: 94 read, 571 written · 8 s · 69.6 tok/s
Write exactly three lines about a marsh. Use the word marsh in every line. Start every line with the letter b, and do not use any of these words: volcano, forest, quarry, park, beach, tundra, plateau, delta, kitchen or reef. Every line must be entirely lowercase, and the third line must end with a question mark. Output only the three lines.
b bright reeds sway in the marsh b quiet water mirrors the marsh at dusk b does the marsh whisper secrets?
Exact JSON shapePassed
324 tokens: 68 read, 256 written · 4 s · 72.1 tok/s
Return a JSON object with exactly two keys: "words", a list of exactly 2 different lowercase words that each start with the letter y and use only the plain letters a to z, and "count", the number 2. Output only the JSON.
{ "words": ["yellow", "yarn"], "count": 2 }Sort a listFailed
157 tokens: 52 read, 105 written · 1 s · 71.2 tok/s
Sort these words alphabetically, ignoring case. Output only the sorted words, on one line separated by commas: Onion, corn, squash, Carrot, rice.
corn, carrot, onion, rice, squash
A name with three rulesPassed
927 tokens: 78 read, 849 written · 12 s · 72.8 tok/s
Suggest a product name for a solar-powered fan. Rules: exactly two words, both capitalized, using only the plain letters A to Z, the first word starts with the letter P, the second word starts with the letter F, and the letter b must not appear anywhere. Output only the name.
Pulse Fan
Reasoning 5 of 5
Unit pricePassed
259 tokens: 61 read, 198 written · 3 s · 61.6 tok/s
A shop sells pencils at 5 for $1.50. How much do 9 pencils cost, in dollars? Work it out, then end with a line "ANSWER: <number>".
First, find the cost of one pencil. - 5 pencils cost $1.50, so one pencil costs \( \frac{1.50}{5} = 0.30 \) dollars. Next, calculate the cost of 9 pencils. - \( 9 \times 0.30 = 2.70 \) dollars. ANSWER: 2.70Day and datePassed
2,252 tokens: 75 read, 2,177 written · 29 s · 75.4 tok/s
Today is Tuesday, 8 December 2026. What day of the week, and what date, is it 319 days from today? Work it out, then end with a line "ANSWER: <day of the week>, <YYYY-MM-DD>".
ANSWER: Saturday, 2027-10-23
Who owns each petPassed
597 tokens: 180 read, 417 written · 6 s · 72.7 tok/s
Five people, Lea, Hal, Dee, Eli and Jon, each own exactly one of these pets: a cat, a dog, a fish, a bird and a rabbit. Each pet has one owner. Clues: - Jon does not own the fish. - Hal owns the cat or the fish. - Hal owns the cat. - Dee owns the bird or the rabbit. - Dee does not own the cat. - Jon owns the cat or the bird. - Lea does not own the fish. Who owns each pet? Work it out, then end with a line "ANSWER: <owner of the cat>, <owner of the dog>, <owner of the fish>, <owner of the bird>, <owner of the rabbit>", with the five names in that order, separated by commas.
ANSWER: Hal, Lea, Eli, Jon, Dee
Arrival timePassed
265 tokens: 71 read, 194 written · 5 s · 41.1 tok/s
A train leaves at 07:45 and the trip takes 5 hours 45 minutes. At what time does it arrive? Work it out, then end with a line "ANSWER: <HH:MM>" in 24-hour time.
The train departs at 07:45. Add the travel time: - 5 hours after 07:45 is 12:45. - Adding the remaining 45 minutes gives 13:30. Thus the arrival time is 13:30 in 24‑hour format. ANSWER: 13:30
Filling a tankPassed
373 tokens: 98 read, 275 written · 4 s · 78.5 tok/s
A tank holds 442 liters and starts empty. Pipe A adds 22 liters an hour, pipe B adds 14 liters an hour, and a drain takes 23 liters an hour out of it. With all three open, how many hours until the tank is full? Work it out, then end with a line "ANSWER: <number>".
The net filling rate when all three are open is: - Pipe A: +22 L/h - Pipe B: +14 L/h - Drain: ‑23 L/h Net rate = 22 + 14 − 23 = **13 L/h**. Time to fill 442 L at 13 L/h: \[ \text{time} = \frac{442\text{ L}}{13\text{ L/h}} = 34\text{ h} \] ANSWER: 34
Reading code 4 of 4
What does it printPassed
352 tokens: 93 read, 259 written · 4 s · 64.5 tok/s
What numbers does this Python program print, in order? Work it out, then end with a line "ANSWER: <numbers, separated by commas>". def f(xs): return sorted(xs)[::-1][:3] print(f([11, 16, 31, 12, 3, 33]))ANSWER: 33, 31, 16
Trace a loopPassed
960 tokens: 97 read, 863 written · 10 s · 85.4 tok/s
What does this Python program print? Work it out, then end with a line "ANSWER: <output>". def g(n): total = 0 for i in range(1, n + 1): if i % 2 == 0 or i % 3 == 0: total += i return total print(g(85))ANSWER: 2394
Find the bugPassed
456 tokens: 122 read, 334 written · 5 s · 73 tok/s
The function count_even should return how many of the numbers in a list are even. The code below has one bug. Find the line with the bug, and write that line corrected, exactly as it should read in the code. Work it out, then end with a line "ANSWER: <corrected line>". def count_even(amounts): count = 0 for x in amounts: if x % 3 == 0: count += 1 return countANSWER: if x % 2 == 0:
Run a query in your headPassed
381 tokens: 148 read, 233 written · 3 s · 73.4 tok/s
What rows does this SQL query return? Output only the rows, one per line, as customer,total in the query's order. Table orders: id | customer | amount 1 | ben | 10 2 | cal | 65 3 | ana | 115 4 | cal | 90 5 | ana | 10 6 | ben | 60 Query: SELECT customer, SUM(amount) AS total FROM orders GROUP BY customer HAVING SUM(amount) > 100 ORDER BY total DESC;
cal,155 ana,125
Using tools 5 of 5
Call one toolPassed
1,042 tokens: 731 read, 311 written · 5 s · 60.2 tok/s
What's the weather in Osaka right now, in celsius?
- user
What's the weather in Osaka right now, in celsius?
- assistant
get_weather({"city":"Osaka","unit":"celsius"}) - tool
{"city": "Osaka", "conditions": "rainy", "temperature": 19, "unit": "celsius"} - assistant
The current weather in Osaka is 19°C with rainy conditions. You might want to carry an umbrella!
- user
Don't call a tool when none is neededPassed
671 tokens: 460 read, 211 written · 4 s · 47.3 tok/s
What is 13 times 22?
- user
What is 13 times 22?
- assistant
The result of 13 times 22 is 286. <final_answer> 286 </final_answer>
- user
Two calls for two answersPassed
1,384 tokens: 868 read, 516 written · 7 s · 69 tok/s
Convert 710 CHF to EUR and to JPY.
- user
Convert 710 CHF to EUR and to JPY.
- assistant
convert_currency({"amount":710,"from":"CHF","to":"EUR"})convert_currency({"amount":710,"from":"CHF","to":"JPY"}) - tool
{"amount": 755.32, "currency": "EUR"} - tool
{"amount": 121229, "currency": "JPY"} - assistant
710 CHF is equivalent to: - **755.32 EUR** (Euro) - **121,229 JPY** (Japanese Yen) These conversions are based on today's exchange rates. Let me know if you need further assistance!
- user
Chain two toolsPassed
1,957 tokens: 1,276 read, 681 written · 14 s · 47.7 tok/s
What is the status of each order for the customer with the email ruth.abara@example.com?
- user
What is the status of each order for the customer with the email ruth.abara@example.com?
- assistant
find_customer({"email":"ruth.abara@example.com"}) - tool
{"customer_id": "C-3087", "name": "Ruth Abara"} - assistant
get_orders({"customer_id":"C-3087"}) - tool
{"orders": [{"order_id": "A-83", "status": "delivered"}, {"order_id": "A-63", "status": "cancelled"}]} - assistant
The orders for customer Ruth Abara (ID: C-3087) are: - Order A-83: Delivered - Order A-63: Cancelled
- user
Handle a failed call honestlyPassed
1,552 tokens: 824 read, 728 written · 14 s · 51.1 tok/s
Book a table for 2 people at Taverna Sol tonight at 19:00. If that time is not free, do not book another time without asking me first.
- user
Book a table for 2 people at Taverna Sol tonight at 19:00. If that time is not free, do not book another time without asking me first.
- assistant
book_table({"people":2,"restaurant":"Taverna Sol","time":"19:00"}) - tool
{"available_times": ["18:30", "20:30"], "error": "fully booked at that time"} - assistant
The requested time of 19:00 is not available. Available times are 18:30 and 20:30. Please let me know which time you'd like to book.
- user
Building pages 5 of 5
A small websitePassed
2,343 tokens: 197 read, 2,146 written · 27 s · 78.1 tok/s
Build a one-page website for a bakery called "Golden Bread Co". It must have a <header> containing an <h1> with the bakery's name; a <nav> with exactly 3 links; a <main> with a <section id="menu"> listing at least 4 items in a list, including Croissant, Rye loaf, Seeded roll and Pecan danish; and a <footer> with the opening hours. Output one complete HTML document and nothing else. Put all CSS and JavaScript inline. Do not load anything from another site: no external scripts, stylesheets, fonts or images. Do not link to a file by a relative path either: no src, href or url() that names a file next to the page. Do not hide anything with CSS: no display: none, visibility: hidden or opacity: 0.
Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Golden Bread Co</title> <style> body {font-family:Arial,Helvetica,sans-serif; margin:0; padding:0; background:#f9f9f9;} header {background:#ffd700; padding:15px; text-align:center;} header h1 {margin:0; font-size:2em; color:#333;} nav ul {list-style:none; padding:0; margin:0; display:flex; justify-content:center; gap:15px;} nav a {text-decoration:none; color:#fff; padding:8px 12px; background:#006400; border-radius:4px; font-weight:bold;} main {padding:20px; max-width:800px; margin:auto;} #menu ul {list-style-type:disc; margin-left:20px; padding:0;} #menu li {margin-bottom:8px; font-size:1.1em;} footer {background:#333; color:#fff; text-align:center; padding:10px; margin-top:30px;} </style> </head> <body> <header> <h1>Golden Bread Co</h1> </header> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">Menu</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <main> <section id="menu"> <h2>Menu</h2> <ul> <li>Croissant</li> <li>Rye loaf</li> <li>Seeded roll</li> <li>Pecan danish</li> </ul> </section> </main> <footer> <p>Opening Hours: Mon‑Fri 7 am – 7 pm, Sat 8 am – 6 pm, Sun 9 am – 5 pm</p> </footer> <script> console.log('Golden Bread Co page loaded'); </script> </body> </html>A pricing table with a togglePassed
4,985 tokens: 222 read, 4,763 written · 1 min 5 s · 73.4 tok/s
Build a pricing page with three plans, in this order: Pro at $18 a month or $180 a year, Solo at $23 a month or $230 a year and Plus at $28 a month or $280 a year. Each plan is an element with class "plan" containing an element with class "price". Show the monthly prices first, and write the words monthly and yearly as text in the markup, not as CSS content. Add a <button id="billing-toggle"> that switches every price between monthly and yearly billing when clicked. Output one complete HTML document and nothing else. Put all CSS and JavaScript inline. Do not load anything from another site: no external scripts, stylesheets, fonts or images. Do not link to a file by a relative path either: no src, href or url() that names a file next to the page. Do not hide anything with CSS: no display: none, visibility: hidden or opacity: 0.
Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pricing Plans</title> <style> body {font-family:Arial,Helvetica,sans-serif; margin:20px;} .plan {border:1px solid #333; padding:15px; margin-bottom:15px; width:300px;} .plan h3 {margin-top:0; font-size:1.2em;} .price {font-size:1.5em; font-weight:bold; margin:0;} button {padding:10px 20px; font-size:1em; cursor:pointer; margin-top:20px;} </style> </head> <body> <button id="billing-toggle">Toggle billing</button> <div class="plan"> <h3>Pro</h3> <div class="price" data-monthly-text="$18 monthly" data-yearly-text="$180 yearly"> $18 monthly </div> </div> <div class="plan"> <h3>Solo</h3> <div class="price" data-monthly-text="$23 monthly" data-yearly-text="$230 yearly"> $23 monthly </div> </div> <div class="plan"> <h3>Plus</h3> <div class="price" data-monthly-text="$28 monthly" data-yearly-text="$280 yearly"> $28 monthly </div> </div> <script> let isMonthly = true; document.getElementById('billing-toggle').addEventListener('click', function() { isMonthly = !isMonthly; const priceElements = document.querySelectorAll('.price'); priceElements.forEach(function(el) { if (isMonthly) { el.textContent = el.getAttribute('data-monthly-text'); } else { el.textContent = el.getAttribute('data-yearly-text'); } }); }); </script> </body> </html>An accessible sign-up formPassed
1,812 tokens: 256 read, 1,556 written · 20 s · 78.9 tok/s
Build a sign-up form for Pine Books. Put the brand name in a heading above the form. The form is <form id="signup"> with inputs id="name", id="email" (type email) and id="password" (type password, minlength at least 8), each with a <label for>, and a submit button. Give the form a novalidate attribute, and check the fields yourself when it is submitted. If the email is not a valid address, or the password is shorter than 8 characters, do not send the form; show a message in an element with id="status" and role="status" that says what is wrong. If the form is valid, prevent the real submission and leave the status element empty. Output one complete HTML document and nothing else. Put all CSS and JavaScript inline. Do not load anything from another site: no external scripts, stylesheets, fonts or images. Do not link to a file by a relative path either: no src, href or url() that names a file next to the page. Do not hide anything with CSS: no display: none, visibility: hidden or opacity: 0.
Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pine Books Signup</title> <style> body {font-family: Arial, sans-serif; margin: 20px;} label {display: block; margin-top: 10px;} input {margin-top: 5px; padding: 5px; width: 100%; max-width: 300px;} button {margin-top: 15px; padding: 10px 20px;} #status {margin-top: 10px; color: red;} </style> </head> <body> <h1>Pine Books</h1> <form id="signup" novalidate> <label for="name">Name</label> <input type="text" id="name" name="name"> <label for="email">Email</label> <input type="email" id="email" name="email"> <label for="password">Password</label> <input type="password" id="password" name="password" minlength="8"> <button type="submit">Sign Up</button> <div id="status" role="status" aria-live="polite"></div> </form> <script> document.getElementById('signup').addEventListener('submit', function(e) { e.preventDefault(); // prevent real submission const name = document.getElementById('name').value.trim(); const email = document.getElementById('email').value.trim(); const password = document.getElementById('password').value; let valid = true; let message = ''; // email validation const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailPattern.test(email)) { valid = false; message = 'Please enter a valid email address.'; } // password length validation if (password.length < 8) { valid = false; message = 'Password must be at least 8 characters long.'; } const statusEl = document.getElementById('status'); if (!valid) { statusEl.textContent = message; } else { statusEl.textContent = ''; } }); </script> </body> </html>A to-do app that remembersPassed
1,895 tokens: 187 read, 1,708 written · 25 s · 68.6 tok/s
Build a to-do list app called "Garage jobs". Show its name in a heading. The app has an <input id="new-task">, a <button id="add"> and a <ul id="tasks">. Clicking add appends the text as an <li> with its own remove button. Save the list in localStorage under the key "todos" and load it again when the page opens. Output one complete HTML document and nothing else. Put all CSS and JavaScript inline. Do not load anything from another site: no external scripts, stylesheets, fonts or images. Do not link to a file by a relative path either: no src, href or url() that names a file next to the page. Do not hide anything with CSS: no display: none, visibility: hidden or opacity: 0.
Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Garage jobs</title> <style> body {font-family:Arial,sans-serif;margin:20px;} h1 {margin-bottom:10px;} #new-task {padding:5px;width:300px;} #add {padding:5px 10px;margin-left:5px;} ul {list-style:none;padding:0;margin-top:10px;} li {margin:5px 0;display:flex;align-items:center;} .remove-btn {margin-left:auto;background:red;color:white;border:none;padding:2px 6px;cursor:pointer;} </style> </head> <body> <h1>Garage jobs</h1> <input id="new-task" type="text" placeholder="Enter task"> <button id="add">Add</button> <ul id="tasks"></ul> <script> const input = document.getElementById('new-task'); const addBtn = document.getElementById('add'); const tasksUl = document.getElementById('tasks'); const STORAGE_KEY = 'todos'; function loadTasks() { const data = localStorage.getItem(STORAGE_KEY); if (data) { try { const tasks = JSON.parse(data); tasks.forEach(text => { const li = document.createElement('li'); li.textContent = text; const remove = document.createElement('button'); remove.className = 'remove-btn'; remove.textContent = 'Remove'; remove.onclick = () => { li.remove(); saveTasks(); }; li.appendChild(remove); tasksUl.appendChild(li); }); } catch (e) { console.error('Failed to parse tasks', e); } } } function saveTasks() { const items = []; const liElements = tasksUl.querySelectorAll('li'); liElements.forEach(li => items.push(li.textContent.trim())); localStorage.setItem(STORAGE_KEY, JSON.stringify(items)); } addBtn.addEventListener('click', () => { const text = input.value.trim(); if (text) { const li = document.createElement('li'); li.textContent = text; const remove = document.createElement('button'); remove.className = 'remove-btn'; remove.textContent = 'Remove'; remove.onclick = () => { li.remove(); saveTasks(); }; li.appendChild(remove); tasksUl.appendChild(li); input.value = ''; saveTasks(); } }); input.addEventListener('keypress', e => { if (e.key === 'Enter') { addBtn.click(); } }); loadTasks(); </script> </body> </html>A bar chart in SVGPassed
3,313 tokens: 241 read, 3,072 written · 49 s · 63.3 tok/s
Draw an inline SVG bar chart of lattes sold, in this order: Mon 44, Tue 10, Wed 22, Thu 21 and Fri 39. Give the <svg> a width and a height, and a <title> or an aria-label. Each bar is a <rect class="bar"> whose height attribute is proportional to its value, and every bar is inside the <svg>. Each bar is labelled with its day or month in a <text> element under the bar. Write the bars and labels directly in the SVG markup, not with JavaScript. Do not move, resize or hide them with a transform or with CSS. Output one complete HTML document and nothing else. Put all CSS and JavaScript inline. Do not load anything from another site: no external scripts, stylesheets, fonts or images. Do not link to a file by a relative path either: no src, href or url() that names a file next to the page. Do not hide anything with CSS: no display: none, visibility: hidden or opacity: 0.
Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Lattes Chart</title> <style> .bar { fill: steelblue; } text { font-family: sans-serif; font-size: 12px; fill: black; text-anchor: middle; } </style> </head> <body> <svg width="500" height="200" aria-label="Lattes sold per day"> <title>Lattes sold per day</title> <!-- Monday --> <rect class="bar" x="50" y="30" width="30" height="150"/> <text x="65" y="185">Mon</text> <!-- Tuesday --> <rect class="bar" x="90" y="30" width="30" height="34"/> <text x="105" y="69">Tue</text> <!-- Wednesday --> <rect class="bar" x="130" y="30" width="30" height="75"/> <text x="145" y="110">Wed</text> <!-- Thursday --> <rect class="bar" x="170" y="30" width="30" height="72"/> <text x="185" y="107">Thu</text> <!-- Friday --> <rect class="bar" x="210" y="30" width="30" height="133"/> <text x="225" y="168">Fri</text> </svg> </body> </html>
Building games 0 of 4
Build 2048Failed
17,757 tokens: 457 read, 17,300 written · 4 min 46 s · 60.4 tok/s
Build the game 2048 as one web page, playable with the arrow keys, with the board drawn on the page. In <script id="game">, define createGame() returning an object with move(dir) and state(). dir is "up", "down", "left" or "right". state() returns {board, score, over}: board is 4 rows of 4 numbers, top row first (0 is an empty cell), score is a number, over is a boolean. The rules, exactly: 1. The board starts as this one, then a 2 is put in each of the first two empty cells in reading order (row by row from the top, left to right). The score starts at 0. [4, 0, 0, 8] [0, 16, 0, 4] [32, 2, 0, 0] [0, 0, 0, 16] 2. A move slides every tile as far as it goes toward dir. Two tiles of the same value that meet merge into one tile of their sum, nearest the side they move toward first: moving left, [2,2,2,2] becomes [4,4,0,0] and [2,2,2,0] becomes [4,2,0,0]. A tile made by a merge does not merge again in the same move. 3. Each merge adds the new tile's value to the score. 4. If a move changed the board, a 2 is put in the first empty cell in reading order. A move that changes nothing does nothing. 5. over is true when no move would change the board; then moves do nothing. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>2048</title> <style> body {font-family:Arial,sans-serif; display:flex; flex-direction:column; align-items:center; margin-top:20px;} #board {border-collapse:collapse; margin-bottom:10px;} #board td {width:100px; height:100px; border:1px solid #333; text-align:center; vertical-align:middle; font-size:2em; line-height:100px;} #board td:not(:empty) {background:#fff;} #board td:empty {background:#f0f0f0;} #score {font-size:1.5em; margin-bottom:10px;} #msg {margin-top:10px; font-weight:bold;} </style> </head> <body> <div id="msg"></div> <div id="score">0</div> <table id="board"> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> </table> <script id="game"> function createGame() { // initial board let board = [ [4,0,0,8], [0,16,0,4], [32,2,0,0], [0,0,0,16] ]; // place two 2s in the first two empty cells (reading order) let empties = []; for (let r = 0; r < 4 && empties.length < 2; r++) { for (let c = 0; c < 4; c++) { if (board[r][c] === 0) { empties.push([r, c]); } } } empties.forEach(([r, c]) => { board[r][c] = 2; }); let score = 0; let over = false; function deepCopy(arr) { return arr.map(row => row.slice()); } function move(dir) { if (over) return; let newBoard = deepCopy(board); let changed = false; if (dir === 'left' || dir === 'right' || dir === 'up' || dir === 'down') { if (dir === 'left' || dir === 'right') { // process rows for (let r = 0; r < 4; r++) { let row = newBoard[r]; let list = row.filter(v => v !== 0); let merged = false; let newList = []; if (dir === 'left') { for (let i = 0; i < list.length; i++) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } } else { // right for (let i = list.length - 1; i >= 0; i--) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } newList.reverse(); // restore left‑to‑right order } // fill new row with zeros let newRow = new Array(4).fill(0); if (dir === 'left' || dir === 'up') { for (let i = 0; i < newList.length; i++) newRow[i] = newList[i]; } else { for (let i = 0; i < newList.length; i++) { newRow[4 - newList.length + i] = newList[i]; } } row = newRow; } } else { // process columns for (let c = 0; c < 4; c++) { let col = []; for (let r = 0; r < 4; r++) col.push(newBoard[r][c]); let list = col.filter(v => v !== 0); let merged = false; let newList = []; if (dir === 'up') { for (let i = 0; i < list.length; i++) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } } else { // down for (let i = list.length - 1; i >= 0; i--) { if (newList.length && newList[newList.length - 1] === list[i] && !merged) { let sum = newList.pop() + list[i]; newList.push(sum); score += sum; merged = true; } else { newList.push(list[i]); merged = false; } } newList.reverse(); } // fill new column with zeros let newCol = new Array(4).fill(0); if (dir === 'up' || dir === 'left') { for (let i = 0; i < newList.length; i++) newCol[i] = newList[i]; } else { for (let i = 0; i < newList.length; i++) { newCol[4 - newList.length + i] = newList[i]; } } for (let r = 0; r < 4; r++) { newBoard[r][c] = newCol[r] || 0; } } } // check if the board changed for (let r = 0; r < 4; r++) { for (let c = 0; c < 4; c++) { if (newBoard[r][c] !== board[r][c]) { changed = true; break; } } if (changed) break; } if (changed) { // place a new 2 in the first empty cell (reading order) let placed = false; for (let r = 0; r < 4 && !placed; r++) { for (let c = 0; c < 4; c++) { if (newBoard[r][c] === 0) { newBoard[r][c] = 2; placed = true; break; } } } board = newBoard; over = false; } else { over = true; } } return { board, score, over }; } function state() { return { board: deepCopy(board), score: score, over: over }; } return { move, state }; } </script> <script> /* wiring */ const game = createGame(); function render() { const { board, score, over } = game.state(); const table = document.getElementById('board'); for (let r = 0; r < 4; r++) { for (let c = 0; c < 4; c++) { const cell = table.rows[r].cells[c]; const val = board[r][c]; cell.textContent = val === 0 ? '' : val; cell.style.background = (val === 0) ? '#f0f0f0' : '#fff'; } } document.getElementById('score').textContent = score; document.getElementById('msg').textContent = over ? 'Game over' : ''; } // initial render render(); // key handling window.addEventListener('keydown', e => { let dir; if (e.key === 'ArrowUp') dir = 'up'; else if (e.key === 'ArrowDown') dir = 'down'; else if (e.key === 'ArrowLeft') dir = 'left'; else if (e.key === 'ArrowRight') dir = 'right'; else return; const result = game.move(dir); render(); }); </script> </body> </html>Build SnakeFailed
10,155 tokens: 458 read, 9,697 written · 2 min 31 s · 64.4 tok/s
Build Snake as one web page on a 10 by 10 grid, playable with the arrow keys (one key press, one step), with the grid drawn on the page. In <script id="game">, define createGame() returning an object with step(dir) and state(). dir is "up", "down", "left" or "right". state() returns {snake, food, score, over}: snake is a list of [x, y] cells, head first; food is [x, y]; score is a number; over is a boolean. x is the column (0 to 9, left to right), y the row (0 to 9, top to bottom); up is y - 1. The rules, exactly: 1. The game starts with snake [[5, 3], [6, 3], [7, 3]], moving left, food at [3, 6], score 0. 2. step(dir): if dir is the opposite of the current direction it is ignored and the snake keeps going; otherwise dir becomes the current direction. The head moves one cell that way. 3. If the new head cell holds the food, the snake grows: its tail stays. Otherwise the tail cell is freed first. 4. If the new head is off the grid or on a cell of the snake (after rule 3), the game is over: over becomes true and nothing else changes. Once over, step does nothing. 5. Eating adds 1 to the score, and the next food goes to the first empty cell in reading order (row by row from the top, left to right) after the new head's cell, wrapping from [9, 9] to [0, 0]. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Snake</title> <style> #grid { display: grid; grid-template-columns: repeat(10, 30px); grid-template-rows: repeat(10, 30px); border: 2px solid black; width: 300px; height: 300px; } #grid div { width: 30px; height: 30px; background-color: #f0f0f0; } </style> </head> <body> <div id="grid"></div> <script id="game"> function createGame() { let snake = [[5,3],[6,3],[7,3]]; let direction = 'left'; let food = [3,6]; let score = 0; let over = false; const bounds = (x,y) => x>=0 && x<10 && y>=0 && y<10; return { step(dir) { if (over) return; // ignore opposite direction if ((dir==='up' && direction==='down') || (dir==='down' && direction==='up') || (dir==='left' && direction==='right') || (dir==='right' && direction==='left')) { // keep current direction } else { direction = dir; } // compute new head let head = snake[0]; let nx = head[0]; let ny = head[1]; if (direction==='up') ny--; else if (direction==='down') ny++; else if (direction==='left') nx--; else if (direction==='right') nx++; // check bounds if (!bounds(nx,ny)) { over = true; return; } // check food let ate = false; if (nx===food[0] && ny===food[1]) { ate = true; score++; } // remove tail if not eating if (!ate) { snake.pop(); } // add new head snake.unshift([nx,ny]); // self collision if (snake.slice(1).some(c=>c[0]===nx && c[1]===ny)) { over = true; return; } // place new food if ate if (ate) { // find next empty cell after new head in reading order let nx2 = nx, ny2 = ny; let nextX = nx2 + 1; let nextY = ny2; if (nextX > 9) { nextX = 0; nextY++; } if (nextY > 9) { nextX = 0; nextY = 0; } let startIdx = nextY*10 + nextX; outer: for (let offset=0; offset<100; offset++) { let idx = (startIdx + offset) % 100; let y = Math.floor(idx/10); let x = idx % 10; if (!snake.some(seg=>seg[0]===x && seg[1]===y)) { food = [x,y]; break outer; } } // fallback (should not happen) if (!food) { outer: for (let y=0; y<10; y++) { for (let x=0; x<10; x++) { if (!snake.some(seg=>seg[0]===x && seg[1]===y)) { food = [x,y]; break outer; } } } } } }, state() { return {snake, food, score, over}; } }; } </script> <script> const game = createGame(); document.addEventListener('keydown', e => { const dirMap = { ArrowUp: 'up', ArrowDown: 'down', ArrowLeft: 'left', ArrowRight: 'right' }; if (dirMap[e.key]) { game.step(dirMap[e.key]); } }); </script> </body> </html>Box-pushing puzzleFailed
15,304 tokens: 1,121 read, 14,183 written · 3 min 41 s · 64.3 tok/s
Build a box-pushing puzzle as one web page on an 8 by 7 grid, playable with the arrow keys, with the level drawn on the page. Give the page and its heading the title Box-pushing puzzle. In <script id="game">, define createGame() returning an object with walk(dir) and state(). dir is "up", "down", "left" or "right". state() returns {player, boxes, pushes, steps, solved}: player is [x, y]; boxes is a list of [x, y] sorted by row, then column; pushes and steps are numbers; solved is a boolean. x is the column (0 to 7, left to right), y the row (0 to 6, top to bottom); up is y - 1. The level, row 0 first, 8 characters to a row (a space is empty floor; the outer ring is all wall): ``` ######## ## # # ##### # #+$ .# # $ * # # # ######## ``` # wall, space floor, . goal, $ box, * box on a goal, @ player, + player on a goal. The rules, exactly: 1. The game starts with this level, steps 0, pushes 0 and solved false. Walls and goals never change. 2. walk(dir) moves the player one cell in dir. If that cell is a wall, nothing changes and nothing is counted. A goal is floor, so the player can stand on one. 3. If that cell holds a box, the box moves one cell further in dir and the player takes the box's old cell. This push happens only if the cell beyond the box is empty floor or a goal: not a wall and not another box. Otherwise nothing changes and nothing is counted. 4. A walk that moves the player adds 1 to steps. A push is a walk too, so it adds 1 to pushes as well. 5. solved is true when every box is on a goal. Once solved, walk does nothing. The page: the arrow keys do the same walks as walk(dir), one walk for each key press (a key that repeats while held walks once). Four buttons with data-dir="up", data-dir="down", data-dir="left" and data-dir="right" do the same walks. Label them Up, Down, Left and Right, laid out like the arrow keys: Up above Down, with Left, Down and Right in one row. A button with id="restart", labelled Restart, starts the level over, with steps and pushes back at 0. The board is an element with id="board". It holds one element per cell, 56 in all, row by row from the top, 8 to a row, and nothing else. Each cell has role="img" and an aria-label that names what it holds: wall, empty floor, empty goal, box, box on a goal, you or you on a goal. Every cell except empty floor also shows a visible character as its text, so that a wall, a goal, a box and you can each be seen (the character is yours to choose). Show the steps in an element with id="steps" and the pushes in one with id="pushes", each as a plain number. The status line is an element with id="status". Until the level is solved, it must not say that it is solved (a line such as Not solved yet is fine). Once it is, it says solved, with the number of steps next to the word steps and the number of pushes next to the word pushes, for example: Solved in 12 steps with 3 pushes. A tenth of a second after each key press, button press or Restart, the board, the steps, the pushes and the status line show what state() says. A page may draw on the next animation frame or after a timer. The page must not use eval or Function, must not give a timer a string of text (a timer takes a function), must not add a script element to the page, must not set an event attribute such as onclick from text, and must not make network requests or load anything from another site: no fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon or importScripts, and no image or file from another site. The whole page must be under 65,536 characters, and the script with id="game" under 20,000 characters. Light background; walls dark, goals ringed, boxes and the player easy to tell apart. Tell a box on a goal from one off a goal by a mark or shape, not by colour alone. The two scripts share one global scope, so give the page's copy of the map another name than the logic's (a const MAP in both stops the second script with an error), or wrap the page's script in a function. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Box-pushing puzzle</title> <style> #board {display:grid;grid-template-columns:repeat(8,30px);grid-template-rows:repeat(7,30px);gap:2px;} #board > div {width:30px;height:30px;line-height:30px;text-align:center;font-family:sans-serif;background:#eee;} .wall {background:#000;color:#fff;} .empty {background:#eee;} .goal {background:#0f0;} .box {background:#f00;} .box-on-goal {background:#ff0;} .player {background:#00f;} </style> </head> <body> <h1>Box-pushing puzzle</h1> <div id="board"></div> <div id="steps">0</div> <div id="pushes">0</div> <div id="status">Not solved yet</div> <button id="restart">Restart</button> <button data-dir="up">Up</button> <button data-dir="down">Down</button> <button data-dir="left">Left</button> <button data-dir="right">Right</button> <script id="game"> const MAP = `######## ## # # ##### # +$ .# # $ * # # # ########`.trim().split('\n'); const ROWS = MAP.length, COLS = MAP[0].length; const goalMask = []; for (let y=0; y<ROWS; y++) { goalMask[y] = []; for (let x=0; x<COLS; x++) { const ch = MAP[y][x]; goalMask[y][x] = (ch === '.' || ch === '+' || ch === '*'); } } function createGame() { let player = null; let boxes = []; for (let y=0; y<ROWS; y++) { for (let x=0; x<COLS; x++) { const ch = MAP[y][x]; if (ch === '+' || ch === '@') { player = [x,y]; } else if (ch === '$') { boxes.push([x,y]); } else if (ch === '*') { boxes.push([x,y]); } } } boxes.sort((a,b)=>a[1]-b[1]||a[0]-b[0]); let pushes = 0, steps = 0, solved = false; const state = () => ({player, boxes, pushes, steps, solved}); const walk = dir => { if (solved) return; const dirs = {up:{0,-1},down:{0,1},left:-1,right:1}; const [dx,dy] = dirs[dir]; const [px,py] = player; const nx = px+dx, ny = py+dy; if (MAP[ny][nx] === '#') return; const boxIdx = boxes.findIndex(b=>b[0]===nx && b[1]===ny); if (boxIdx !== -1) { const bx = nx+dx, by = ny+dy; if (MAP[by][bx] === '#') return; if (boxes.some((b,i)=>i!==boxIdx && b[0]===bx && b[1]===by)) return; boxes[boxIdx] = [bx,by]; pushes++; } player = [nx,ny]; steps++; solved = boxes.every(b => { const cell = MAP[b[1]][b[0]]; return cell === '.' || cell === '*' || cell === '+'; }); }; return {walk, state}; } </script> <script> const game = createGame(); const board = document.getElementById('board'); const stepsEl = document.getElementById('steps'); const pushesEl = document.getElementById('pushes'); const statusEl = document.getElementById('status'); const restartBtn = document.getElementById('restart'); function draw(state) { board.innerHTML = ''; for (let y=0; y<ROWS; y++) { for (let x=0; x<COLS; x++) { const isGoal = goalMask[y][x]; const cell = document.createElement('div'); cell.setAttribute('role','img'); let char = ''; let cls = ''; if (state.player[0]===x && state.player[1]===y) { char = '+'; cls = 'player'; } else { const box = state.boxes.find(b=>b[0]===x && b[1]===y); if (box) { if (isGoal) { char = '*'; cls = 'box-on-goal'; } else { char = '$'; cls = 'box'; } } else { if (isGoal) { char = '.'; cls = 'goal'; } else { char = MAP[y][x]; cls = (MAP[y][x] === '#') ? 'wall' : 'empty'; } } } cell.className = cls; cell.textContent = char; let label = ''; if (cls === 'wall') label = 'wall'; else if (cls === 'empty') label = 'empty floor'; else if (cls === 'goal') label = 'goal'; else if (cls === 'box') label = 'box'; else if (cls === 'box-on-goal') label = 'box on goal'; else if (cls === 'player') label = 'player'; else label = 'empty'; cell.setAttribute('aria-label', label); board.appendChild(cell); } } } function scheduleUpdate() { setTimeout(() => { const s = game.state(); stepsEl.textContent = s.steps; pushesEl.textContent = s.pushes; if (s.solved) statusEl.textContent = `Solved in ${s.steps} steps with ${s.pushes} pushes`; else statusEl.textContent = 'Not solved yet'; draw(s); }, 100); } document.addEventListener('keydown', e => { if (e.key === 'ArrowUp') { game.walk('up'); scheduleUpdate(); } else if (e.key === 'ArrowDown') { game.walk('down'); scheduleUpdate(); } else if (e.key === 'ArrowLeft') { game.walk('left'); scheduleUpdate(); } else if (e.key === 'ArrowRight') { game.walk('right'); scheduleUpdate(); } }); document.querySelectorAll('button[data-dir]').forEach(btn => { btn.addEventListener('click', () => { const dir = btn.dataset.dir; game.walk(dir); scheduleUpdate(); }); }); restartBtn.addEventListener('click', () => { game = createGame(); scheduleUpdate(); }); </script> </body> </html>MinesweeperFailed
24,828 tokens: 1,438 read, 23,390 written · 5 min 22 s · 72.6 tok/s
Build Minesweeper as one web page: a 9 by 9 board with 10 mines, in the layout below, with the board drawn on the page. In <script id="game">, define createGame() returning an object with press(move) and state(). The site plays the game more than once, calling createGame() again each time, so every game starts from the layout. move is an array [kind, row, col]: kind is "open" or "flag", row is 0 (top) to 8 (bottom), col is 0 (left) to 8 (right). state() returns {cells, status, mines_left}: cells is 9 strings of 9 characters, one per row from the top. A character is "#" for a hidden cell, "F" for a flagged cell, "." for an opened cell with no mines around it, "1" to "8" for an opened cell with that many mines among the 8 cells around it, and "*" for a mine after a loss. status is "playing", "won" or "lost". mines_left is 10 minus the number of flagged cells, and can be negative. The mines, row by row from the top. In this layout * is a mine and . is a safe cell. row 0 *.......* row 1 ......... row 2 ........* row 3 ......... row 4 ..*...... row 5 ....***.. row 6 ......... row 7 ..***.... row 8 ......... The rules, exactly: 1. The game starts with every cell hidden, no flags, and status "playing". 2. press(["open", r, c]) on a hidden cell opens it. If it is a mine, status becomes "lost" and every mine shows "*", flagged or not. Otherwise the cell shows its number, or "." when no mine is among the cells around it. 3. An opened cell with no mines around it also opens each hidden, unflagged cell around it (8 directions). Each of those with no mines around it opens its own hidden, unflagged neighbours the same way, repeatedly, until nothing more opens. A flagged cell is never opened this way, and nothing spreads from it. A numbered cell opens, but nothing spreads from it. 4. press(["open", r, c]) on a flagged cell or an opened cell does nothing. 5. press(["flag", r, c]) on a hidden cell flags it. On a flagged cell it removes the flag, and the cell is hidden again. On an opened cell it does nothing. 6. status becomes "won" when every cell without a mine is opened, however the last cell is opened. A flag does not count: a flagged cell without a mine must be unflagged and opened. After a win every mine shows "F" and counts as flagged, whether or not the player flagged it, so mines_left is 0. 7. Once status is "won" or "lost", press does nothing. After a loss a flag still counts in mines_left, even on a mine that shows "*", and a flag on a safe cell still shows "F". The page: a title, a short paragraph of rules, then one white panel holding a status line, a Flag mode button and the board, on a warm off-white page. The type is the system sans-serif (font-family: system-ui, sans-serif); load no font. Give these parts these names, so the site can read them: - an element with role="status": it shows "Mines left" and mines_left as a number, with a minus sign when it is below zero, then the status word, "Playing", "Won" (green) or "Lost" (red); - a button with id="flag-mode": it starts with the text "Flag mode: off" and aria-pressed="false". When it is on, its text is "Flag mode: on", aria-pressed="true", and it is drawn in the pink accent; - the board, which is either 81 cell buttons, each with data-row (0 at the top to 8) and data-col (0 at the left to 8), or one canvas that draws all of it, with the id board: 324 pixels across and down (set its width and height attributes), nine squares of 36 pixels each way, row 0 at the top and column 0 at the left. On a canvas, a click or a right-click acts on the square under the pointer: find the square from the event's offsetX and offsetY, each scaled by the canvas's width over its clientWidth (or its height over its clientHeight), since a phone may draw the canvas smaller. A click on a cell calls press(["open", row, col]) for that cell, unless Flag mode is on: then it calls press(["flag", row, col]). A right-click on a cell (the contextmenu event) calls press(["flag", row, col]) and prevents the browser's own menu. Draw the board from state() after every press: a hidden or empty cell shows no text, a numbered cell shows its number, and a flag or a mine shows a mark with text in it (a symbol, or a word hidden from sight). On a canvas, clear the whole canvas and draw it again after every press, the cells in reading order (row 0 first, columns left to right): a numbered cell as its number in text, a flag or a mine as one short mark in text (F, *, or another plain symbol), and a hidden or empty cell as nothing; the canvas draws nothing else. Flags and mines are simple marks, not emoji. The page fits a phone with no sideways scrolling. A reload of the page starts a new game: every cell is hidden, no flag is set, Flag mode is off and the status reads "Playing", so nothing from the last load is kept. The keyboard is welcome but not checked: Tab moves between cells, Enter or Space opens one, and F flags it. The page runs its own code only: no eval, no Function(), no timer given as text, and no network request (fetch, XMLHttpRequest, WebSocket, EventSource, sendBeacon or importScripts). It loads nothing from another site. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Minesweeper</title> <style> body { font-family: system-ui, sans-serif; background-color: #f5f0e6; margin: 0; padding: 20px; display: flex; flex-direction: column; align-items: center; } h1 { margin-bottom: 10px; } p.rules { margin-bottom: 20px; max-width: 600px; text-align: center; } #status { margin-bottom: 10px; font-weight: bold; } #flag-mode { margin-bottom: 10px; padding: 8px 12px; font-size: 1rem; cursor: pointer; } #board { width: 324px; height: 324px; border: 2px solid #333; background-color: #fff; } </style> </head> <body> <h1>Minesweeper</h1> <p class="rules"> Click or press Enter/Space to open a cell. In Flag mode, click or press F to toggle a flag. Right‑click (or contextmenu) also toggles a flag. The game starts with all cells hidden, 9 mines (as per layout), 10 mines left, and status “Playing”. </p> <div role="status" id="status">Mines left: 9 Playing</div> <button id="flag-mode" aria-pressed="false">Flag mode: off</button> <canvas id="board" width="324" height="324"></canvas> <script id="game"> function createGame() { const rows = [ "*.......*", ".........", "........*", ".........", "..*......", "....**...", ".........", "..***....", "........." ]; const n = 9; // build mine grid const isMineGrid = Array.from({length:n}, () => Array(n).fill(false)); for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (rows[r][c] === '*') { isMineGrid[r][c] = true; } } } // compute adjacent counts for non-mine cells const countGrid = Array.from({length:n}, () => Array(n).fill(0)); for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (!isMineGrid[r][c]) { for (let dr = -1; dr <= 1; dr++) { for (let dc = -1; dc <= 1; dc++) { if (dr === 0 && dc === 0) continue; const nr = r + dr, nc = c + dc; if (nr >= 0 && nr < n && nc >= 0 && nc < n && isMineGrid[nr][nc]) { countGrid[r][c]++; } } } } } } // cell objects const cells = []; for (let r = 0; r < n; r++) { cells[r] = []; for (let c = 0; c < n; c++) { cells[r][c] = { isMine: isMineGrid[r][c], revealed: false, flagged: false, count: countGrid[r][c] }; } } let status = "playing"; let mines_left = isMineGrid.flat().filter(v => v).length; // total mines // helper to count flagged cells function countFlagged() { let cnt = 0; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (cells[r][c].flagged) cnt++; } } return cnt; } // recursive open function openCell(r, c) { const cell = cells[r][c]; if (cell.revealed || cell.flagged) return; cell.revealed = true; if (cell.count === 0) { for (let dr = -1; dr <= 1; dr++) { for (let dc = -1; dc <= 1; dc++) { if (dr === 0 && dc === 0) continue; const nr = r + dr, nc = c + dc; if (nr >= 0 && nr < n && nc >= 0 && nc < n) { const neighbor = cells[nr][nc]; if (!neighbor.revealed && !neighbor.flagged) { openCell(nr, nc); } } } } } } // press handler function press(move) { if (status !== "playing") return; const [kind, r, c] = move; if (kind === "flag") { if (r < 0 || r >= n || c < 0 || c >= n) return; const cell = cells[r][c]; if (cell.revealed) return; if (cell.flagged) { cell.flagged = false; } else { cell.flagged = true; } } else if (kind === "open") { if (r < 0 || r >= n || c < 0 || c >= n) return; const cell = cells[r][c]; if (cell.flagged || cell.revealed) return; if (cell.isMine) { status = "lost"; // reveal all mines for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (cells[i][j].isMine) { cells[i][j].revealed = true; } } } // mines_left unchanged return; } else { openCell(r, c); } } // check win condition let win = true; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { const cell = cells[r][c]; if (cell.isMine) { if (status === "won") { if (!cell.flagged) win = false; } else { win = false; } } else { if (!cell.revealed) { win = false; } if (cell.flagged) { win = false; } } } } if (win) { status = "won"; // force flag all mines for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { if (cells[r][c].isMine) { cells[r][c].flagged = true; } } } mines_left = 0; } // update mines_left mines_left = isMineGrid.flat().filter(v => v).length - countFlagged(); } // state getter function state() { const rowsStr = []; for (let r = 0; r < n; r++) { let row = ''; for (let c = 0; c < n; c++) { const cell = cells[r][c]; let ch = ''; if (cell.flagged) { ch = 'F'; } else if (cell.revealed) { if (cell.isMine) { if (status === 'lost') { ch = '*'; } } else { if (cell.count === 0) { ch = '.'; } else { ch = cell.count.toString(); } } } else { ch = '#'; } row += ch; } rowsStr.push(row); } return { cells: rowsStr, status: status, mines_left: mines_left }; } return { press, state }; } </script> <script> /* UI wiring */ const game = createGame(); const statusEl = document.getElementById('status'); const flagBtn = document.getElementById('flag-mode'); const canvas = document.getElementById('board'); let flagMode = false; let selectedRow = -1, selectedCol = -1; // draw board from current game state function drawBoard() { const state = game.state(); const ctx = canvas.getContext('2d'); ctx.clearRect(0, 0, canvas.width, canvas.height); const n = 9; for (let r = 0; r < n; r++) { for (let c = 0; c < n; c++) { const cell = state.cells[r][c]; const x = c * 36; const y = r * 36; let charToDraw = ''; if (cell.flagged) { charToDraw = 'F'; } else if (cell.revealed) { if (cell.isMine) { if (state.status === 'lost') { charToDraw = '*'; } } else { if (cell.count === 0) { charToDraw = '.'; } else { charToDraw = cell.count.toString(); } } } if (charToDraw) { ctx.fillStyle = 'black'; ctx.font = '30px system-ui, sans-serif'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(charToDraw, x + 18, y + 18); } } } } // update status line function updateStatus() { const s = game.state(); const mins = s.mines_left; const statusWord = s.status; const color = (statusWord === 'Won') ? 'green' : (statusWord === 'Lost') ? 'red' : 'black'; statusEl.textContent = `Mines left: ${mins} ${statusWord}`; statusEl.style.color = color; } // flag mode button flagBtn.addEventListener('click', () => { flagMode = !flagMode; flagBtn.textContent = flagMode ? 'Flag mode: on' : 'Flag mode: off'; flagBtn.setAttribute('aria-pressed', flagMode); flagBtn.style.backgroundColor = flagMode ? '#ff69b4' : ''; flagBtn.style.color = flagMode ? 'white' : 'black'; }); // canvas click canvas.addEventListener('click', e => { const rect = canvas.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const col = Math.floor(x / 36); const row = Math.floor(y / 36); if (row >= 0 && row < 9 && col >= 0 && col < 9) { selectedRow = row; selectedCol = col; if (flagMode) { game.press(['flag', row, col]); } else { game.press(['open', row, col]); } drawBoard(); updateStatus(); } }); // canvas contextmenu (right-click) canvas.addEventListener('contextmenu', e => { e.preventDefault(); const rect = canvas.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const col = Math.floor(x / 36); const row = Math.floor(y / 36); if (row >= 0 && row < 9 && col >= 0 && col < 9) { selectedRow = row; selectedCol = col; game.press(['flag', row, col]); drawBoard(); updateStatus(); } }); // keyboard handling document.addEventListener('keydown', e => { if (selectedRow === -1) return; if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); game.press(['open', selectedRow, selectedCol]); drawBoard(); updateStatus(); } else if (e.key.toLowerCase() === 'f' && flagMode) { e.preventDefault(); game.press(['flag', selectedRow, selectedCol]); drawBoard(); updateStatus(); } }); // initial draw drawBoard(); updateStatus(); </script> </body> </html>
Building apps 0 of 4
Step sequencerFailed
22,342 tokens: 1,322 read, 21,020 written · 5 min 5 s · 68.9 tok/s
Build a web page called "Step sequencer": three rows labelled Kick, Snare and Hat, of 16 step buttons each, a Play button and a Stop button, and drums made with the Web Audio API, with no sound files. In <script id="game">, define createGame() returning an object with press(cmd) and state(). The page calls createGame() at load or on the first press. The logic keeps the pattern, whether it is playing, the playhead and the hits. The page makes the sound. Do not use eval or Function, and never run text as code: give a timer a function, not a string. The starting pattern, one row per track. Steps are numbered from 1 in the rows below: each row is 16 characters, 1 for on and 0 for off. The first character is step 1 on the page and step 0 for press(): kick 1000100010001000 snare 0000100000001100 hat 1010101010101010 The rules, exactly: 1. At the start, playing is false, playhead is 0 and hits is []. 2. press([track, step]) toggles one cell: track 0 is kick, 1 snare, 2 hat; step is 0 to 15, where 0 is the first step. Toggling changes the pattern and nothing else. 3. press('play') does nothing when playing is already true. Otherwise it sets playing to true, and hits becomes the list of track numbers (0 kick, 1 snare, 2 hat) whose cell at the playhead is 1, in ascending order ([] when there are none). So the step under the playhead sounds as play starts. 4. press('stop') sets playing to false, playhead to 0 and hits to []. 5. press('tick') does nothing unless playing is true. When it is, playhead goes on by one, and after 15 it goes back to 0. hits becomes the list of track numbers whose cell at the new playhead is 1, in ascending order ([] when there are none). 6. Any other cmd does nothing: a list that is not exactly two whole numbers (such as [0, 1, 2], [1], [] or [true, 0]), null, a number, true or false, a word other than play, stop or tick, and a track or step outside the ranges above. Track and step are whole numbers. state() returns {playing, playhead, hits, pattern}: playing is true or false; playhead is 0 to 15; hits lists the track numbers set by the last tick or by the play that started playback, in ascending order ([] at the start and after stop); pattern is three strings of 16 characters, kick first, each character 1 or 0. The page: - Each step button is a real button with the attributes data-track (0, 1 or 2) and data-step (0 to 15), and aria-pressed set to true or false to match its state. A click calls press([track, step]), and after every press, the page draws from state(). - A step that is on has the class on, and the stylesheet fills it dark; a step that is off has no class on. - Play has the id play and Stop the id stop. Play calls press('play') and starts one timer that calls press('tick') every 125 ms: 120 quarter-note beats a minute, four steps to a beat. Stop calls press('stop') and clears the timer. Each play and each tick sounds the hits that state() then reports, and nothing else sounds. - Play has the disabled attribute while playing, and Stop has it while stopped. - A status line with the id status reads "Stopped", or "Playing, step N of 16" with N the playhead plus 1. Give it a fixed height, so the grid does not move when its text changes. - A span with the id announce, set to aria-live polite, is empty until playback starts for the first time. From then on it says "Playing" when playback starts and "Stopped" when it stops, and changes at no other time. - The cells in the playhead column have the class playhead while playing, and no cell has it while stopped. - The numbers 1 to 16, as text, sit above the grid, and the playhead's number is pink. Under 720 px each step shows its number. - When the page becomes hidden, it presses Stop, so nothing sounds in a background tab. - Each track in hits plays its drum: kick is a falling sine tone, snare a short noise burst with a low body tone, hat a short high noise burst. Tones use oscillators; noise bursts use buffer sources playing a buffer of random samples: the kick is one oscillator, the snare one buffer source and one oscillator, the hat one buffer source. Hits that land together must not clip, so put a gain or a limiter before the output. Create the AudioContext inside the first click (browsers need a click before they make sound), and resume it if it is suspended. - Flat and plain: a light background, dark ink, no shadows or gradients, Play the one pink button (#b31f57), and the playhead cell outlined in pink where you are. At 1280 px the 16 steps sit in one row; under 720 px they form two bars of 8. The page never scrolls sideways. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and drives the sequencer through createGame(). Wire the page in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Step sequencer</title> <style> body { background:#f0f0f0; margin:0; padding:10px; font-family:Arial,Helvetica,sans-serif; overflow:hidden; } #status { height:30px; font-weight:bold; margin-top:10px; } #announce { display:none; } #play, #stop { margin-right:5px; padding:8px 16px; border:none; cursor:pointer; } #play { background:#b31f57; color:#fff; } #stop { background:#555; color:#fff; } .grid-wrapper { display:flex; flex-direction:column; align-items:center; margin-top:10px; } .step-numbers { display:flex; justify-content:center; margin-bottom:5px; } .num { width:30px; text-align:center; line-height:30px; font-size:14px; } .grid { display:grid; grid-template-columns: repeat(16, 1fr); gap:2px; margin-bottom:5px; } @media (max-width:720px) { .grid { grid-template-columns: repeat(8, 1fr); } } .step { width:30px; height:30px; border:1px solid #999; background:#fff; cursor:pointer; } .step.on { background:#111; color:#fff; } .step.playhead { outline:2px solid #b31f57; } </style> </head> <body> <script id="game"> function createGame() { let pattern = [ "1000100010001000", "0000100000001100", "1010101010101010" ]; let playing = false; let playhead = 0; let hits = []; function ensureAudioContext() { if (!AudioContext && !webkitAudioContext) return; if (!audioContext) { audioContext = new AudioContext(); if (audioContext.state === "suspended") { audioContext.resume(); } } } function playHits() { ensureAudioContext(); const gain = audioContext.createGain(); gain.connect(audioContext.destination); hits.forEach(track => { const t = track; if (t === 0) { const osc = audioContext.createOscillator(); osc.type = "sine"; osc.frequency.value = 100; osc.connect(gain); osc.start(); osc.stop(audioContext.currentTime + 0.2); } else if (t === 1) { const bodyOsc = audioContext.createOscillator(); bodyOsc.type = "sawtooth"; bodyOsc.frequency.value = 110; const bodyGain = audioContext.createGain(); bodyOsc.connect(bodyGain); bodyGain.connect(gain); bodyOsc.start(); bodyOsc.stop(audioContext.currentTime + 0.1); bodyGain.gain.setValueAtTime(0.001, audioContext.currentTime); bodyGain.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.2); const bufferLength = 1024; const noiseBuffer = audioContext.createBuffer(1, bufferLength, audioContext.sampleRate); const data = noiseBuffer.getChannelData(0); for (let i = 0; i < bufferLength; i++) { data[i] = Math.random() * 2 - 1; } const noiseSource = audioContext.createBufferSource(); noiseSource.buffer = noiseBuffer; const noiseGain = audioContext.createGain(); noiseSource.connect(noiseGain); noiseGain.connect(gain); noiseSource.start(); noiseSource.stop(audioContext.currentTime + 0.05); } else if (t === 2) { const bufferLength = 512; const noiseBuffer = audioContext.createBuffer(1, bufferLength, audioContext.sampleRate); const data = noiseBuffer.getChannelData(0); for (let i = 0; i < bufferLength; i++) { data[i] = Math.random() * 2 - 1; } const noiseSource = audioContext.createBufferSource(); noiseSource.buffer = noiseBuffer; const noiseGain = audioContext.createGain(); noiseSource.connect(noiseGain); noiseGain.connect(gain); noiseSource.start(); noiseSource.stop(audioContext.currentTime + 0.03); } }); } function press(cmd) { if (Array.isArray(cmd)) { if (cmd.length === 2) { const [track, step] = cmd; if (typeof track === "number" && typeof step === "number" && track >= 0 && track <= 2 && step >= 0 && step <= 15) { const idx = track; const current = pattern[idx][step]; pattern[idx] = current === "1" ? "0" : "1"; } } } else if (cmd === "play") { if (!playing) { playing = true; hits = []; for (let t = 0; t < 3; t++) { if (pattern[t][playhead] === "1") hits.push(t); } hits.sort((a,b)=>a-b); playHits(); } } else if (cmd === "stop") { if (playing) { playing = false; hits = []; playhead = 0; } } else if (cmd === "tick") { if (playing) { playhead = (playhead + 1) % 16; hits = []; for (let t = 0; t < 3; t++) { if (pattern[t][playhead] === "1") hits.push(t); } hits.sort((a,b)=>a-b); playHits(); } } } function state() { return { playing, playhead, hits, pattern }; } return { press, state }; } </script> <script> document.addEventListener('DOMContentLoaded', () => { const game = createGame(); // status line const status = document.createElement('div'); status.id = 'status'; status.style.height = '30px'; status.style.fontWeight = 'bold'; status.textContent = 'Stopped'; document.body.appendChild(status); // announce span const announce = document.createElement('span'); announce.id = 'announce'; announce.setAttribute('aria-live', 'polite'); document.body.appendChild(announce); // play button const playBtn = document.createElement('button'); playBtn.id = 'play'; playBtn.textContent = 'Play'; playBtn.disabled = true; document.body.appendChild(playBtn); // stop button const stopBtn = document.createElement('button'); stopBtn.id = 'stop'; stopBtn.textContent = 'Stop'; stopBtn.disabled = true; document.body.appendChild(stopBtn); // grid wrapper const gridWrapper = document.createElement('div'); gridWrapper.className = 'grid-wrapper'; document.body.appendChild(gridWrapper); // step numbers const stepNumbers = document.createElement('div'); stepNumbers.className = 'step-numbers'; for (let i = 1; i <= 16; i++) { const span = document.createElement('span'); span.className = 'num'; span.textContent = i; stepNumbers.appendChild(span); } gridWrapper.appendChild(stepNumbers); // create rows for each track const tracks = [0,1,2]; tracks.forEach(track => { const row = document.createElement('div'); row.className = 'grid'; row.dataset.track = track; for (let step = 0; step < 16; step++) { const btn = document.createElement('button'); btn.type = 'button'; btn.className = 'step'; btn.dataset.track = track; btn.dataset.step = step; const pattern = game.state().pattern[track]; const isOn = pattern[step] === '1'; btn.setAttribute('aria-pressed', isOn); if (isOn) btn.classList.add('on'); btn.addEventListener('click', () => { game.press([track, step]); drawUI(); }); row.appendChild(btn); } gridWrapper.appendChild(row); }); let firstPlay = true; let tickInterval = null; function drawUI() { const state = game.state(); const { playing, playhead, hits, pattern } = state; // update button states const rows = gridWrapper.querySelectorAll('.grid'); rows.forEach((row, trackIdx) => { const track = parseInt(row.dataset.track); const patternStr = pattern[track]; const buttons = row.querySelectorAll('button'); buttons.forEach((btn, step) => { const isOn = patternStr[step] === '1'; btn.setAttribute('aria-pressed', isOn); if (isOn) btn.classList.add('on'); else btn.classList.remove('on'); if (playing && step === playhead) { btn.classList.add('playhead'); } else { btn.classList.remove('playhead'); } }); }); // play/stop button disabled playBtn.disabled = playing; stopBtn.disabled = !playing; // status text if (playing) { status.textContent = `Playing, step ${playhead + 1} of 16`; if (firstPlay) { announce.textContent = 'Playing'; firstPlay = false; } } else { status.textContent = 'Stopped'; announce.textContent = 'Stopped'; } } function startTick() { if (tickInterval) return; tickInterval = setInterval(() => { game.press('tick'); drawUI(); }, 125); } function stopTick() { if (tickInterval) { clearInterval(tickInterval); tickInterval = null; } } playBtn.addEventListener('click', () => { game.press('play'); drawUI(); startTick(); }); stopBtn.addEventListener('click', () => { game.press('stop'); drawUI(); stopTick(); }); document.addEventListener('visibilitychange', () => { if (document.hidden) { game.press('stop'); drawUI(); stopTick(); } }); drawUI(); }); </script> </body> </html>Grow a branching plantFailed
13,860 tokens: 1,249 read, 12,611 written · 3 min 8 s · 67 tok/s
Build a plant that grows by a rewrite rule (an L-system) as one web page: a heading, a canvas that draws the plant, a Grow button and a Reset button. In <script id="game">, define createGame() returning an object with grow() and state(). grow() takes no argument. state() returns {generation, text, segments}: generation is a number, text is a string, and segments is a list with one [x1, y1, x2, y2] entry for each F in text, in the order the Fs appear in text. [x1, y1] is the cell a segment starts from and [x2, y2] the cell it ends on. The rules, exactly: 1. A pen starts at [0, 0] facing north, which is heading 6. Headings are numbered 0 to 7 clockwise, each one a step [dx, dy] with y growing downward: 0 [1, 0] east, 1 [1, 1] south-east, 2 [0, 1] south, 3 [-1, 1] south-west, 4 [-1, 0] west, 5 [-1, -1] north-west, 6 [0, -1] north, 7 [1, -1] north-east. 2. The text starts as F, at generation 0. The pen reads the text from left to right. F moves the pen one step along its heading and adds the segment [x1, y1, x2, y2] for that step. + adds 1 to the heading and - subtracts 1, both modulo 8. [ saves the pen's position and heading. ] restores the last saved position and heading and forgets them. Any other symbol does nothing. 3. grow() rewrites the text in one pass: every F becomes F[[++F]+F[--F]]F, and every other symbol stays as it is. The Fs that the rule adds are not rewritten in that pass. Then generation goes up by 1. 4. segments is what the pen draws over the new text, starting again at [0, 0] facing north, as in rule 1. 5. At the start, generation is 0, text is "F" and segments is [[0, 0, 0, -1]]. 6. grow() at generation 4 changes nothing: generation, text and segments stay as they are. The site calls grow() five times in a row, and reads state() before the first call and after each call, so every state must match these rules. The fifth call is made at generation 4. Keep the rule in the game script as one string, written exactly as rule 3 gives it: the site also runs the script with another rule in its place, and its states must follow that rule. The page: a heading (an <h1>) reading exactly "Grow a branching plant". Below it, one canvas draws each segment as a line from its start point to its end point, with the context's own moveTo, lineTo and stroke (not Path2D). The canvas draws nothing else: no other shapes, no text and no images. The drawing has the shape the segments give, with north up on the canvas: one scale on both axes, fitted to the canvas and centred. Each drawing starts by clearing the whole canvas (clearRect over all of it, or setting the canvas's width), so only the new plant is on it. Each press of Grow draws the whole plant again, at once, with one lineTo for each segment: no animation frames and no delays. The plant is drawn when the page loads, and Reset draws the stem again within a tenth of a second. Grow is a <button id="grow"> reading exactly "Grow". A press calls grow(), then draws and shows the new state, and Grow is disabled at generation 4. Reset is a <button id="reset"> reading exactly "Reset". A press calls createGame() for a new plant, draws it, and enables Grow again. Wire both with addEventListener('click', ...). A status line, an element with role="status", reads "Generation g of 4, n segments", where g is the generation and n the number of segments (the word is "segment" when n is 1), and it changes after each press. Look: plain and tidy, like a small app. A light, warm off-white page, the canvas in a white card with a thin border, the plant in dark ink, Grow as the main button and Reset as an outlined button under the card. The page must work at 390 px and at 1280 px wide with no sideways scrolling. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not use document, window, localStorage, sessionStorage or any timer, because the site runs that script on its own and plays the game through createGame(). The script is at most 20,000 characters. Wire the page in another <script>. Neither script may use eval or Function, reach Function through a constructor, or give a timer text to run; and neither may read window, self, globalThis, top, parent, frames or this with square brackets. A constructor() method in a class is fine, and so is a constructor key in an object; reading a constructor property, as x.constructor or x['constructor'], is not. A timer is given a function: one written in the call, or one the page declares by name. Square brackets take a number or a name, never quoted text, and window is used only as window.name.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Grow a branching plant</title> <style> body { background:#f5f0e6; font-family:sans-serif; margin:0; display:flex; flex-direction:column; align-items:center; } .card { background:#fff; border:1px solid #ccc; padding:10px; margin:20px; max-width:100%; box-sizing:border-box; } h1 { text-align:center; margin:0; } canvas { display:block; width:100%; height:auto; background:#fff; } button#grow { padding:8px 16px; font-size:1rem; } button#reset { padding:8px 16px; font-size:1rem; border:1px solid #ccc; background:transparent; } #status { margin-top:10px; text-align:center; font-size:0.9rem; } </style> </head> <body> <h1>Grow a branching plant</h1> <div class="card"> <canvas id="canvas"></canvas> <div id="status" role="status"></div> </div> <button id="grow">Grow</button> <button id="reset">Reset</button> <script id="game"> function createGame() { let generation = 0; let text = "F"; let segments = []; const dirs = [ [1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1] ]; function computeSegments() { let x = 0, y = 0; let heading = 6; // north const stack = []; const segs = []; for (let i = 0; i < text.length; i++) { let c = text[i]; if (c === 'F') { let dx = dirs[heading][0]; let dy = dirs[heading][1]; segs.push([x, y, x + dx, y + dy]); x += dx; y += dy; } else if (c === '+') { heading = (heading + 1) % 8; } else if (c === '-') { heading = (heading + 7) % 8; } else if (c === '[') { stack.push({x, y, heading}); } else if (c === ']') { let saved = stack.pop(); x = saved.x; y = saved.y; heading = saved.heading; } } return segs; } segments = computeSegments(); return { grow() { if (generation === 4) { return; } let newText = ''; for (let i = 0; i < text.length; i++) { let c = text[i]; if (c === 'F') { newText += "F[[++F]+F[--F]]F"; } else { newText += c; } } text = newText; generation++; segments = computeSegments(); }, state() { return {generation, text, segments}; } }; } </script> <script> const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); const status = document.querySelector('[role="status"]'); const growBtn = document.getElementById('grow'); const resetBtn = document.getElementById('reset'); function resizeCanvas() { const rect = canvas.parentElement.getBoundingClientRect(); canvas.width = Math.round(rect.width); canvas.height = Math.round(rect.height); } function drawPlant(game) { ctx.clearRect(0, 0, canvas.width, canvas.height); const segs = game.state().segments; ctx.strokeStyle = 'black'; segs.forEach(s => { ctx.beginPath(); ctx.moveTo(s[0], s[1]); ctx.lineTo(s[2], s[3]); ctx.stroke(); }); } function updateStatus(game) { const {generation, segments} = game.state(); const n = segments.length; const word = n === 1 ? 'segment' : 'segments'; status.textContent = `Generation ${generation} of 4, ${n} ${word}`; } function initGame() { const game = createGame(); drawPlant(game); updateStatus(game); growBtn.disabled = false; growBtn.addEventListener('click', () => { game.grow(); drawPlant(game); updateStatus(game); growBtn.disabled = (game.state().generation >= 4); }); resetBtn.addEventListener('click', () => { const newGame = createGame(); drawPlant(newGame); updateStatus(newGame); growBtn.disabled = false; }); } window.addEventListener('load', () => { resizeCanvas(); window.addEventListener('resize', resizeCanvas); initGame(); }); </script> </body> </html>Falling sandFailed
13,342 tokens: 1,142 read, 12,200 written · 2 min 43 s · 74.9 tok/s
Build a page called Falling sand: a 40 by 30 board drawn on a canvas. Sand falls one frame at a time and slides off the edges of piles. Pressing or dragging on the board pours sand, Play runs the frames, and Step runs one. In <script id="game">, define createGame(). It returns an object with play(move) and state(). move is "step" (run one frame) or [x, y] (pour one grain of sand into column x, row y). state() returns {frame, cells}: frame is the number of frames run so far (a pour is not a frame), and cells is 30 rows of 40 numbers, top row first: 0 is empty, 1 is sand, 2 is wall. Column x runs 0 to 39, left to right; row y runs 0 to 29, top to bottom. The start, exactly (both ends of each run are included): 1. frame is 0. Row 29 is all wall. 2. Walls: row 16, columns 10 to 16; row 24, columns 7 to 15; column 31, rows 22 to 26. 3. Sand: column 25, row 1; row 2, columns 22 to 28; row 3, columns 21 to 29; row 4, columns 20 to 30; row 5, columns 21 to 29; row 6, columns 22 to 28; column 25, row 7. 4. Every other cell is empty. The rules, exactly: 1. A pour [x, y] puts one grain in that cell if it is empty; a cell holding sand or wall, or outside the grid, is not empty, so the pour does nothing. 2. A step runs one frame, using frame as it is before the step, then frame goes up by 1. A frame scans the rows from row 28 up to row 0. Within a row it scans the columns from left to right when frame is even, and from right to left when frame is odd. 3. Each sand cell the scan reaches moves at most once: to (x, y+1) if that cell is empty; otherwise to (x-1, y+1) if that is empty; otherwise to (x+1, y+1) if that is empty; otherwise it stays. Anything outside the grid counts as wall. 4. Each check reads the cells as they are at that moment: a grain that has moved leaves its cell empty, and a cell an earlier grain filled in this frame is not empty. The site plays a list of moves through play() and checks state() after each one. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the game logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and plays the game through createGame(). Wire the page in another <script>. Do not run a string as code: no eval, no Function (not even as a function's constructor property), no timer given a string, no javascript: address, and no script element made from text. Network requests are refused, and the game script is at most 20,000 characters. The page: a canvas with the id board and the width and height attributes 640 and 480. The board may be shown at any size and place on the page: a press or drag finds its cell from where the board is on screen not from its 640 by 480 pixels. A press on the board pours one grain into the cell under the pointer. A drag pours into every cell on the straight line from the cell the pointer left to the cell it reached, both ends included (Bresenham's line algorithm). Buttons with the ids play, step and reset. play runs one frame about every 50 ms, and its label reads Pause while it runs; pressing it again pauses, and the label reads Play. step runs one frame. reset calls createGame() again, back to the start, and stops Play if it is running. After each pour, after each frame that Play or Step runs, and after Reset, the board is cleared or filled once, then each grain of sand is drawn with fillRect in its own cell; empty cells are not drawn one by one. One line under the board, with the id status, reads "Frame N, M grains of sand" ("1 grain of sand" for one), N is the frame and M the grains. Not checked, but wanted: keyboard pouring (arrow keys move a pour cursor when the board has focus; Space or Enter pours at it); a live region with the id say that announces Play, Pause, Step and Reset; reduced motion (prefers-reduced-motion: reduce): a press of Play runs one frame; off screen, Play pauses for real (no frame runs, the label reads Play) and resumes on return only if it was playing, and a press of Play then does nothing, while Step still runs one frame.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Falling sand</title> <style> body {font-family:sans-serif; text-align:center; margin-top:20px;} #board {border:1px solid #000; touch-action:none;} #status {margin-top:10px; font-weight:bold;} button {margin:5px; padding:5px 10px;} #say {position:absolute; left:-9999px; top:-9999px;} </style> </head> <body> <canvas id="board" width="640" height="480"></canvas> <div id="status">Frame 0, 0 grains of sand</div> <button id="play">Play</button> <button id="step">Step</button> <button id="reset">Reset</button> <div id="say" aria-live="polite"></div> <script id="game"> function createGame() { let frame = 0; let cells = Array.from({length:30}, () => Array(40).fill(0)); // walls for (let x = 10; x <= 16; x++) cells[16][x] = 2; for (let x = 7; x <= 15; x++) cells[24][x] = 2; for (let y = 22; y <= 26; y++) cells[y][31] = 2; // row 29 all wall for (let x = 0; x < 40; x++) cells[29][x] = 2; // sand initial positions cells[1][25] = 1; for (let x = 22; x <= 28; x++) cells[2][x] = 1; for (let x = 21; x <= 29; x++) cells[3][x] = 1; for (let x = 20; x <= 30; x++) cells[4][x] = 1; for (let x = 21; x <= 29; x++) cells[5][x] = 1; for (let x = 22; x <= 28; x++) cells[6][x] = 1; cells[7][25] = 1; function stepFrame() { for (let y = 28; y >= 0; y--) { const even = (frame % 2 === 0); const cols = even ? Array.from({length:40}, (_,i)=>i) : Array.from({length:40}, (_,i)=>39-i); for (let x of cols) { if (cells[y][x] !== 1) continue; const ny = y + 1; if (ny < 30 && cells[ny][x] === 0) { cells[ny][x] = 1; cells[y][x] = 0; continue; } if (ny < 30 && x-1 >= 0 && cells[ny][x-1] === 0) { cells[ny][x-1] = 1; cells[y][x] = 0; continue; } if (ny < 30 && x+1 < 40 && cells[ny][x+1] === 0) { cells[ny][x+1] = 1; cells[y][x] = 0; continue; } } } frame++; } function play(move) { if (move === "step") { stepFrame(); } else if (Array.isArray(move) && move.length === 2) { const [x, y] = move; if (x >= 0 && x < 40 && y >= 0 && y < 30 && cells[y][x] === 0) { cells[y][x] = 1; } } } function state() { return { frame, cells: cells.map(row => row.slice()) }; } return {play, state}; } </script> <script> const board = document.getElementById('board'); const playBtn = document.getElementById('play'); const stepBtn = document.getElementById('step'); const resetBtn = document.getElementById('reset'); const status = document.getElementById('status'); const say = document.getElementById('say'); let game = createGame(); let isPlaying = false; let intervalId = null; let wasPlayingBeforeHidden = false; function getCellFromEvent(clientX, clientY) { const rect = board.getBoundingClientRect(); const x = Math.floor((clientX - rect.left) / 16); const y = Math.floor((clientY - rect.top) / 16); return [x, y]; } // Bresenham line algorithm (inclusive) function bresenham(x0, y0, x1, y1) { const points = []; let dx = Math.abs(x1 - x0); let dy = Math.abs(y1 - y0); const sx = x0 < x1 ? 1 : -1; const sy = y0 < y1 ? 1 : -1; let err = dx - dy; while (true) { points.push([x0, y0]); if (x0 === x1 && y0 === y1) break; const e2 = 2 * err; if (e2 > -dy) { err -= dy; x0 += sx; } if (e2 < dx) { err += dx; y0 += sy; } } return points; } // draw current board function updateBoard() { const ctx = board.getContext('2d'); ctx.clearRect(0, 0, board.width, board.height); const cells = game.state().cells; const size = 16; // cell size for (let y = 0; y < 30; y++) { for (let x = 0; x < 40; x++) { const v = cells[y][x]; if (v === 1) { ctx.fillStyle = '#C19A6B'; ctx.fillRect(x * size, y * size, size, size); } else if (v === 2) { ctx.fillStyle = '#555'; ctx.fillRect(x * size, y * size, size, size); } } } } // update status text function updateStatus() { const s = game.state(); const frame = s.frame; const cells = s.cells; let sandCount = 0; for (let row of cells) { for (let v of row) if (v === 1) sandCount++; } const txt = sandCount === 1 ? "1 grain of sand" : `${sandCount} grains of sand`; status.textContent = `Frame ${frame}, ${txt}`; } // start / stop playing function startPlaying() { if (isPlaying) return; if (document.hidden) return; isPlaying = true; playBtn.textContent = "Pause"; intervalId = setInterval(() => { game.play("step"); updateBoard(); updateStatus(); say.textContent = "Step"; }, 50); } function stopPlaying() { if (!isPlaying) return; isPlaying = false; playBtn.textContent = "Play"; clearInterval(intervalId); intervalId = null; } function togglePlay() { if (document.hidden) return; if (isPlaying) { stopPlaying(); say.textContent = "Pause"; } else { startPlaying(); say.textContent = "Play"; } } playBtn.addEventListener('click', togglePlay); stepBtn.addEventListener('click', () => { game.play("step"); updateBoard(); updateStatus(); say.textContent = "Step"; }); resetBtn.addEventListener('click', () => { game = createGame(); stopPlaying(); say.textContent = "Reset"; updateBoard(); updateStatus(); }); // optional keyboard pouring let cursorX = 0, cursorY = 0; board.addEventListener('keydown', e => { if (e.key === "ArrowUp") { e.preventDefault(); cursorY = Math.max(0, cursorY - 1); } else if (e.key === "ArrowDown") { e.preventDefault(); cursorY = Math.min(29, cursorY + 1); } else if (e.key === "ArrowLeft") { e.preventDefault(); cursorX = Math.max(0, cursorX - 1); } else if (e.key === "ArrowRight") { e.preventDefault(); cursorX = Math.min(39, cursorX + 1); } else if (e.key === " " || e.key === "Enter") { e.preventDefault(); game.play([cursorX, cursorY]); updateBoard(); updateStatus(); say.textContent = "Pour"; } }); board.focus(); // give canvas focus // mouse handling let dragStart = null; board.addEventListener('mousedown', e => { const [x, y] = getCellFromEvent(e.clientX, e.clientY); game.play([x, y]); // pour at start cell updateBoard(); updateStatus(); say.textContent = "Pour"; dragStart = [x, y]; }); board.addEventListener('mousemove', e => { if (!dragStart) return; const [x2, y2] = getCellFromEvent(e.clientX, e.clientY); const linePoints = bresenham(dragStart[0], dragStart[1], x2, y2); for (const [cx, cy] of linePoints) { game.play([cx, cy]); } updateBoard(); updateStatus(); }); board.addEventListener('mouseup', () => { dragStart = null; }); // visibility change handling for Play pause function updatePlayState() { if (document.hidden) { if (isPlaying) { stopPlaying(); wasPlayingBeforeHidden = true; say.textContent = "Pause"; } } else { if (wasPlayingBeforeHidden) { startPlaying(); wasPlayingBeforeHidden = false; say.textContent = "Play"; } } } document.addEventListener('visibilitychange', updatePlayState); // initial update updateBoard(); updateStatus(); say.textContent = "Ready"; </script> </body> </html>Focus timerFailed
18,352 tokens: 1,110 read, 17,242 written · 3 min 42 s · 77.7 tok/s
Build a focus timer as one web page. Work periods alternate with breaks, and after every few finished work periods the break is long. The page shows the name of the period, the time left, an SVG ring that empties as the time runs down, and how many work periods are done. In <script id="game">, define createGame(). It returns an object with two methods, tick(cmd) and state(). The page's own timer calls tick() once a second, and its buttons call tick('start'), tick('pause'), tick('skip') and tick('reset'). Those four exact lowercase words are commands: they change the timer and pass no time. Any other value passes one second, and only while the timer is running: no argument, null, undefined, a number, true, false, an empty text, any other text such as 'Start' or 'tick', or an object. state() returns {phase, left, running, done}: phase is 'work', 'short' or 'long'; left is the whole number of seconds left in this period; running is true or false; done is a number. The script in <script id="game"> is at most 20,000 characters. This run's lengths: work 1200 seconds (20 minutes), short break 180 seconds (3 minutes), long break 600 seconds (10 minutes). A long break follows every 3rd finished work period. The rules, exactly: 1. The timer starts in work, with left 1200, running false and done 0. 2. 'start' sets running to true, and 'pause' sets it to false. Neither changes anything else. 3. While running, each passed second lowers left by 1. While paused, passed seconds change nothing. 4. When left reaches 0, the period is over at once, so state() never shows 0. The next period starts with its full length and paused (running false). Seconds passed after that change nothing until 'start'. 5. A work period that ends this way adds 1 to done. Then a long break comes when done is a multiple of 3, otherwise a short break. 6. 'skip' ends the current period at once, whatever left is, and the next period starts paused. A skipped work period does not add to done, and the break after it is a short break whatever done is. A skipped break is followed by work. 7. After any break comes work. A break never adds to done. 8. 'reset' sets left back to the full length of the current period and sets running to false. It does not change the phase or done. The page: - A heading, "Focus timer". - The name of the period, alone in an element with the id phase: Focus, Short break or Long break. - The time left, as mm:ss with two digits each, alone in an element with the id time. At the start of this run's work period it reads 20:00. - An SVG ring around the time: a circle with pathLength="100" and stroke-dasharray="100". Set its stroke-dashoffset attribute to 100 times (1 minus left divided by the full length of the current period) on every redraw. The arc is full, with an offset of 0, at the start of a period, and it is empty, with an offset of 100, when the time is up. A track circle without a stroke-dashoffset may sit under it. - Four buttons in one row, with the ids start, pause, skip and reset, labelled Start, Pause, Skip and Reset. Each calls tick() with its command. Start is disabled while the timer runs, and Pause is disabled while it is paused. Skip and Reset are always enabled. Below 390 px they may wrap into two rows of two. - The count in an element with the id count, in words: "Focus periods done: 3". - The page's own timer calls tick() once a second, with no argument. After every call, the page redraws from state(). When a period ends, the page may play a short chime with the Web Audio API. - Look: a light, warm off-white page with one white card, dark ink text and muted grey for the small labels. One accent colour, used for the Start button only. Flat fills, no gradients or shadows, no outside fonts or images: use the system font. It must look tidy at 390 px and at 1280 px wide, with no sideways scrolling. Output one complete HTML document and nothing else, with all CSS and JavaScript inline and nothing loaded from another site. Put the timer's logic, and only it, in <script id="game">: it must not touch document, window or timers, because the site runs that script on its own and drives the timer through createGame(). Do not use eval, Function or any other way of running text as code: no string given to a timer, and no script element or event-handler attribute made from text while the page runs. Put the wiring in another <script>.Open the page on its own. It runs in a sandbox: no network, no access to this site.
Page source
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Focus timer</title> <style> /* Light off‑white background */ body { margin:0; padding:0; background:#f5f0e6; font-family:system-ui, sans-serif; display:flex; justify-content:center; align-items:center; min-height:100vh; } /* White card with dark text */ .card { background:#fff; padding:2rem; border-radius:8px; box-shadow:0 2px 4px rgba(0,0,0,0.1); text-align:center; max-width:300px; width:100%; } /* Heading */ h1 { margin:0 0 1rem; font-size:1.5rem; color:#333; } /* Period name, time and count */ #phase, #time, #count { margin:0.5rem 0; font-size:1.2rem; color:#222; } #phase { font-weight:600; } #time { font-size:2rem; } #count { font-size:1rem; color:#555; } /* Buttons */ .buttons { margin-top:1rem; display:flex; justify-content:center; gap:0.5rem; flex-wrap:wrap; } button { background:#ff6b6b; /* accent colour – only Start */ color:#fff; border:none; border-radius:4px; padding:0.5rem 1rem; font-size:1rem; cursor:pointer; } button:disabled { background:#aaa; cursor:not-allowed; opacity:0.6; } #start:disabled, #pause:disabled { opacity:0.6; } #skip, #reset { background:#6c757d; /* neutral colour */ } #skip:disabled, #reset:disabled { background:#aaa; } /* SVG ring */ #ring { margin-top:1rem; width:120px; height:120px; } /* Responsiveness */ @media (max-width:390px) { .card { padding:1.5rem; } #time { font-size:1.5rem; } } @media (min-width:1280px) { .card { padding:2.5rem; max-width:350px; } } </style> </head> <body> <div class="card"> <h1>Focus timer</h1> <div id="phase">Focus</div> <div id="time">20:00</div> <div class="ring-container"> <svg viewBox="0 0 100 100" style="width:120px;height:120px;position:relative;display:inline-block;"> <circle cx="50" cy="50" r="15.9" stroke="#6c757d" fill="none" stroke-width="5"/> <circle cx="50" cy="50" r="15.9" stroke="#ff6b6b" fill="none" stroke-width="5" id="ring" stroke-dasharray="100"/> </svg> </div> <div id="count">Focus periods done: 0</div> <div class="buttons"> <button id="start" disabled>Start</button> <button id="pause" disabled>Pause</button> <button id="skip">Skip</button> <button id="reset">Reset</button> </div> </div> <script id="game"> function createGame() { let phase = 'work'; let left = 1200; let running = false; let done = 0; function playChime() { if (!window.AudioContext && !window.webkitAudioContext) return; const AudioCtx = window.AudioContext || window.webkitAudioContext; const ctx = new AudioCtx(); const osc = ctx.createOscillator(); osc.type = 'sine'; osc.frequency.value = 440; const gain = ctx.createGain(); osc.connect(gain); gain.connect(ctx.destination); gain.gain.setValueAtTime(0.2, ctx.currentTime); osc.start(ctx.currentTime); osc.stop(ctx.currentTime + 0.1); } function tick(cmd) { if (cmd === 'start') { running = true; } else if (cmd === 'pause') { running = false; } else if (cmd === 'skip') { phase = 'short'; left = 180; running = false; } else if (cmd === 'reset') { if (phase === 'work') left = 1200; else if (phase === 'short') left = 180; else if (phase === 'long') left = 600; running = false; } else { if (running) { left = Math.max(0, left - 1); } } if (left <= 0) { if (phase === 'work') done += 1; if (phase === 'work') { if (done % 3 === 0) { phase = 'long'; left = 600; } else { phase = 'short'; left = 180; } } else { phase = 'work'; left = 1200; } running = false; playChime(); } } function state() { return {phase, left, running, done}; } return {tick, state}; } </script> <script> const game = createGame(); const intervalId = setInterval(() => { game.tick(); // tick with no argument (once per second) const s = game.state(); // update phase name const phaseName = (s.phase === 'work') ? 'Focus' : (s.phase === 'short') ? 'Short break' : 'Long break'; document.getElementById('phase').textContent = phaseName; // update time display (mm:ss) const minutes = Math.floor(s.left / 60); const seconds = s.left % 60; const mm = minutes.toString().padStart(2, '0'); const ss = seconds.toString().padStart(2, '0'); document.getElementById('time').textContent = `${mm}:${ss}`; // update count document.getElementById('count').textContent = `Focus periods done: ${s.done}`; // enable/disable buttons document.getElementById('start').disabled = s.running; document.getElementById('pause').disabled = !s.running; // skip and reset are always enabled // update SVG ring offset const fullLength = (s.phase === 'work') ? 1200 : (s.phase === 'short') ? 180 : 600; const offset = 100 * (1 - s.left / fullLength); const dashOffset = Math.max(0, Math.min(100, offset)); const ring = document.getElementById('ring'); ring.setAttribute('stroke-dashoffset', dashOffset); }, 1000); </script> </body> </html>
Writing code 3 of 3
Merge intervalsPassed
1,015 tokens: 168 read, 847 written · 11 s · 79.9 tok/s
Write a JavaScript function mergeIntervals(intervals). intervals is an array of [start, end] pairs of integers with start <= end, in any order, possibly empty. Return a new array of the merged intervals sorted by start: intervals that overlap or touch (one ends where the next starts) become one. Do not change the input array or its pairs. mergeIntervals([[8, 10], [1, 3], [2, 6], [6, 7]]) returns [[1, 7], [8, 10]]. Reply with one ```js code block holding plain JavaScript (no imports, no exports, no DOM, no timers). The site runs it with hidden tests.
```js function mergeIntervals(intervals) { // Handle empty input if (!Array.isArray(intervals) || intervals.length === 0) return []; // Create a shallow copy of the outer array and copy each interval const copy = intervals.map(pair => pair.slice()); // Sort by the start value copy.sort((a, b) => a[0] - b[0]); const merged = []; let current = copy[0].slice(); // start with the first interval (copy to avoid mutation) for (let i = 1; i < copy.length; i++) { const next = copy[i].slice(); // If intervals overlap or touch, merge them if (next[0] <= current[1]) { current[1] = Math.max(current[1], next[1]); } else { // No overlap, push the current interval and start a new one merged.push(current); current = next; } } // Add the last interval merged.push(current); return merged; } ```An LRU cachePassed
1,197 tokens: 173 read, 1,024 written · 16 s · 65.9 tok/s
Write a JavaScript class LRUCache: a least-recently-used cache of integer keys and values. - new LRUCache(capacity): capacity is an integer of at least 1. - get(key) returns the value stored for key, or -1 if there is none. A get that finds the key makes it the most recently used. - put(key, value) stores the value (replacing any value already there) and makes key the most recently used. If that leaves more than capacity keys, the least recently used key is removed. get and put should take constant time on average. Reply with one ```js code block holding plain JavaScript (no imports, no exports, no DOM, no timers). The site runs it with hidden tests.
```js class LRUCache { constructor(capacity) { if (capacity < 1) throw new Error('capacity must be at least 1'); this.capacity = capacity; this.map = new Map(); // key -> node // Dummy head and tail nodes to simplify edge handling this.head = new Node(0, 0); this.tail = new Node(0, 0); this.head.next = this.tail; this.tail.prev = this.head; } get(key) { const node = this.map.get(key); if (!node) return -1; this._moveToHead(node); return node.value; } put(key, value) { const node = this.map.get(key); if (node) { // Update existing node node.value = value; this._moveToHead(node); } else { // Insert new node const newNode = new Node(key, value); this.map.set(key, newNode); this._addToHead(newNode); // Evict LRU if over capacity if (this.map.size > this.capacity) { const lruNode = this.tail.prev; // least recently used this._removeNode(lruNode); this.map.delete(lruNode.key); } } } // Move a node to the front (most recently used) _moveToHead(node) { this._removeNode(node); this._addToHead(node); } // Add a node right after the head _addToHead(node) { node.prev = this.head; node.next = this.head.next; this.head.next.prev = node; this.head.next = node; } // Remove a node from the list _removeNode(node) { node.prev.next = node.next; node.next.prev = node.prev; } } // Helper class for list nodes class Node { constructor(key, value) { this.key = key; this.value = value; this.prev = null; this.next = null; } } ```Evaluate arithmeticPassed
4,402 tokens: 204 read, 4,198 written · 54 s · 78.2 tok/s
Write a JavaScript function evaluate(expr) that returns the value of an arithmetic expression given as a string. The expression has non-negative integers, the operators + - * /, parentheses, unary minus (as in -3, - -3, 2 * -3 or -(1 + 2)) and spaces anywhere between tokens. * and / bind tighter than + and -, and operators of the same kind group from the left. / is integer division that truncates toward zero: 7 / 2 is 3 and -7 / 2 is -3. Dividing by zero must throw an Error. Do not use eval or Function. evaluate("2 + 3 * (4 - 6) / 4") returns 1. Reply with one ```js code block holding plain JavaScript (no imports, no exports, no DOM, no timers). The site runs it with hidden tests.```js function evaluate(expr) { // ---------- tokenization ---------- const tokens = []; for (let i = 0; i < expr.length; ) { const ch = expr[i]; if (ch === ' ') { i++; continue; } if (ch === '+' || ch === '-' || ch === '*' || ch === '/' || ch === '(' || ch === ')') { tokens.push({type: 'op', value: ch}); i++; continue; } // number let start = i; while (i < expr.length && /[0-9]/.test(expr[i])) i++; tokens.push({type: 'num', value: parseInt(expr.slice(start, i), 10)}); } // ---------- parser ---------- let pos = 0; function next() { return tokens[pos]; } function consume() { return tokens[pos++]; } function parseExpression() { let val = parseTerm(); while (true) { const n = next(); if (n === undefined || n.type !== 'op' || (n.value !== '+' && n.value !== '-')) break; const op = consume(); const right = parseTerm(); if (op.value === '+') val = val + right; else val = val - right; } return val; } function parseTerm() { let val = parseFactor(); while (true) { const n = next(); if (n === undefined || n.type !== 'op' || (n.value !== '*' && n.value !== '/')) break; const op = consume(); const right = parseFactor(); if (op.value === '*') { val = val * right; } else { if (right === 0) throw new Error('Division by zero'); val = Math.trunc(val / right); // truncates toward zero } } return val; } function parseFactor() { const n = next(); if (n !== undefined && n.type === 'op' && n.value === '-') { consume(); return -parseFactor(); } return parsePrimary(); } function parsePrimary() { const n = next(); if (n !== undefined && n.type === 'op' && n.value === '(') { consume(); // '(' const val = parseExpression(); const close = next(); if (close === undefined || close.type !== 'op' || close.value !== ')') { throw new Error('Mismatched parentheses'); } consume(); // ')' return val; } else { const token = consume(); if (token.type !== 'num') { throw new Error('Expected number'); } return token.value; } } return parseExpression(); } ```
Fixing code 2 of 2
Fix the bookings modulePassed
2,595 tokens: 631 read, 1,964 written · 26 s · 76.5 tok/s
This JavaScript module has one bug. Guests are charged the weekend rate for Sunday nights and the weekday rate for Friday nights. Find it and fix it without changing anything else. ```js // Bookings for one holiday flat. A booking is { guest, checkIn, checkOut } with dates as "YYYY-MM-DD". // A guest sleeps the nights from checkIn up to, but not including, checkOut: checkOut is the day they leave, // and another guest may check in that same day. function dayNumber(date) { const [y, m, d] = date.split('-').map(Number); return Date.UTC(y, m - 1, d) / 86400000; } function toDate(day) { return new Date(day * 86400000).toISOString().slice(0, 10); } function nights(booking) { return dayNumber(booking.checkOut) - dayNumber(booking.checkIn); } function overlaps(a, b) { return dayNumber(a.checkIn) < dayNumber(b.checkOut) && dayNumber(b.checkIn) < dayNumber(a.checkOut); } function canBook(bookings, request) { if (nights(request) < 1) return false; for (const booking of bookings) { if (overlaps(booking, request)) return false; } return true; } function isBooked(bookings, day) { return bookings.some((b) => dayNumber(b.checkIn) <= day && day < dayNumber(b.checkOut)); } // The nights from `from` up to, but not including, `to` that someone has booked. function bookedNights(bookings, from, to) { let count = 0; for (let day = dayNumber(from); day < dayNumber(to); day++) { if (isBooked(bookings, day)) count++; } return count; } // The first night on or after `from` that nobody has booked, as "YYYY-MM-DD". function firstFreeNight(bookings, from) { let day = dayNumber(from); while (isBooked(bookings, day)) day++; return toDate(day); } // The price in cents: Friday and Saturday nights at rates.weekend, every other night at rates.weekday. function price(booking, rates) { let total = 0; for (let day = dayNumber(booking.checkIn); day < dayNumber(booking.checkOut); day++) { const weekday = new Date(day * 86400000).getUTCDay(); total += weekday === 6 || weekday === 0 ? rates.weekend : rates.weekday; } return total; } ``` Reply with the whole corrected module in one ```js code block, with the same function names.```js // Bookings for one holiday flat. A booking is { guest, checkIn, checkOut } with dates as "YYYY-MM-DD". // A guest sleeps the nights from checkIn up to, but not including, checkOut: checkOut is the day they leave, // and another guest may check in that same day. function dayNumber(date) { const [y, m, d] = date.split('-').map(Number); return Date.UTC(y, m - 1, d) / 86400000; } function toDate(day) { return new Date(day * 86400000).toISOString().slice(0, 10); } function nights(booking) { return dayNumber(booking.checkOut) - dayNumber(booking.checkIn); } function overlaps(a, b) { return dayNumber(a.checkIn) < dayNumber(b.checkOut) && dayNumber(b.checkIn) < dayNumber(a.checkOut); } function canBook(bookings, request) { if (nights(request) < 1) return false; for (const booking of bookings) { if (overlaps(booking, request)) return false; } return true; } function isBooked(bookings, day) { return bookings.some((b) => dayNumber(b.checkIn) <= day && day < dayNumber(b.checkOut)); } // The nights from `from` up to, but not including, `to` that someone has booked. function bookedNights(bookings, from, to) { let count = 0; for (let day = dayNumber(from); day < dayNumber(to); day++) { if (isBooked(bookings, day)) count++; } return count; } // The first night on or after `from` that nobody has booked, as "YYYY-MM-DD". function firstFreeNight(bookings, from) { let day = dayNumber(from); while (isBooked(bookings, day)) day++; return toDate(day); } // The price in cents: Friday and Saturday nights at rates.weekend, every other night at rates.weekday. function price(booking, rates) { let total = 0; for (let day = dayNumber(booking.checkIn); day < dayNumber(booking.checkOut); day++) { const weekday = new Date(day * 86400000).getUTCDay(); total += weekday === 5 || weekday === 6 ? rates.weekend : rates.weekday; } return total; } ```Fix the CSV readerPassed
2,215 tokens: 474 read, 1,741 written · 36 s · 49 tok/s
This JavaScript module has one bug. A quoted field with a comma in it, such as "Smith, Jane", is split in two. Find it and fix it without changing anything else. ```js // Reads CSV the way spreadsheets write it: fields are separated by commas, a field may be wrapped in // double quotes so it can hold commas, and "" inside a quoted field stands for one double quote. // Fields are not trimmed. Empty lines are skipped. function parseLine(line) { const fields = []; let field = ''; let quoted = false; for (let i = 0; i < line.length; i++) { const ch = line[i]; if (quoted && ch !== ',') { if (ch === '"') { if (line[i + 1] === '"') { field += '"'; i++; } else { quoted = false; } } else { field += ch; } } else if (ch === '"') { quoted = true; } else if (ch === ',') { fields.push(field); field = ''; } else { field += ch; } } fields.push(field); return fields; } function parseCSV(text) { return text.split(/\r?\n/).filter((line) => line !== '').map(parseLine); } // Each row after the header as an object keyed by the header's names; a missing field is ''. function toObjects(text) { const [header, ...rows] = parseCSV(text); return rows.map((row) => { const record = {}; header.forEach((name, i) => { record[name] = i < row.length ? row[i] : ''; }); return record; }); } // The sum of a column's numbers; fields that are not numbers count as 0. function sumColumn(text, name) { return toObjects(text).reduce((total, record) => total + (Number(record[name]) || 0), 0); } ``` Reply with the whole corrected module in one ```js code block, with the same function names.```js // Reads CSV the way spreadsheets write it: fields are separated by commas, a field may be wrapped in // double quotes so it can hold commas, and "" inside a quoted field stands for one double quote. // Fields are not trimmed. Empty lines are skipped. function parseLine(line) { const fields = []; let field = ''; let quoted = false; for (let i = 0; i < line.length; i++) { const ch = line[i]; if (quoted) { if (ch === '"') { if (i + 1 < line.length && line[i + 1] === '"') { field += '"'; i++; } else { quoted = false; } } else { field += ch; } } else if (ch === '"') { quoted = true; } else if (ch === ',') { fields.push(field); field = ''; } else { field += ch; } } fields.push(field); return fields; } function parseCSV(text) { return text.split(/\r?\n/).filter((line) => line !== '').map(parseLine); } // Each row after the header as an object keyed by the header's names; a missing field is ''. function toObjects(text) { const [header, ...rows] = parseCSV(text); return rows.map((row) => { const record = {}; header.forEach((name, i) => { record[name] = i < row.length ? row[i] : ''; }); return record; }); } // The sum of a column's numbers; fields that are not numbers count as 0. function sumColumn(text, name) { return toObjects(text).reduce((total, record) => total + (Number(record[name]) || 0), 0); } ```
Planning and data 3 of 3
A query over hidden dataPassed
617 tokens: 245 read, 372 written · 5 s · 68.5 tok/s
Write one SQLite query that answers the question below. The site runs it on its own copy of these tables, filled with rows you have not seen. ```sql CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT NOT NULL, city TEXT NOT NULL); CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER NOT NULL REFERENCES customers(id), placed TEXT NOT NULL, -- 'YYYY-MM-DD' status TEXT NOT NULL); -- 'delivered', 'cancelled' or 'pending' CREATE TABLE items (order_id INTEGER NOT NULL REFERENCES orders(id), product TEXT NOT NULL, quantity INTEGER NOT NULL, price_cents INTEGER NOT NULL); -- price_cents: for one unit ``` Question: For each city, the total value (quantity times price_cents, summed) of the items in delivered orders placed in 2025. Columns: city, total. Highest total first. Leave out cities with no such items. Reply with only the query, in one ```sql code block: one SELECT statement (WITH is fine), nothing that changes the database.```sql SELECT c.city, SUM(i.quantity * i.price_cents) AS total FROM orders o JOIN customers c ON o.customer_id = c.id JOIN items i ON o.id = i.order_id WHERE o.status = 'delivered' AND o.placed BETWEEN '2025-01-01' AND '2025-12-31' GROUP BY c.city ORDER BY total DESC; ```Schedule five meetingsPassed
6,007 tokens: 300 read, 5,707 written · 1 min 11 s · 80 tok/s
Five people each have one meeting today: Dev, Eli, Gus, Lea, Max. The five meetings are at different times, 09:00, 10:00, 11:00, 13:00, 14:00 (in that order: 10:00 is right after 09:00, 13:00 right after 11:00), and in different rooms. The list of rooms, in order: Birch, Elm, Maple, Rowan, Willow. 1. Dev's and Gus's rooms are next to each other on the list of rooms. 2. Whoever is in Willow meets earlier than Max. 3. Max is not in Rowan. 4. Lea meets neither first nor last. 5. Gus meets earlier than Eli. 6. Dev meets before lunch (before 13:00). 7. Whoever is in Birch meets earlier than Max. 8. Max's meeting is in the slot right after Dev's. 9. Eli's and Lea's rooms are not next to each other on the list of rooms. 10. Gus is not in Willow. Exactly one schedule fits every clue. Work it out, then end with exactly five lines, one per person, in this form: Ana: 09:00, Oak
Dev: 11:00, Willow Eli: 14:00, Maple Gus: 09:00, Rowan Lea: 10:00, Birch Max: 13:00, Elm
A replacement in ten calls or fewerPassed
16,819 tokens: 13,960 read, 2,859 written · 1 min 9 s · 41.4 tok/s
Hi, it's dee.holm@example.com. My kettle arrived with a cracked lid. Can you sort it out?
- system
You are the support agent of Tidewell Home, working through its tools, and you may make at most 10 tool calls for one request. When an item arrives damaged: confirm which order it came in, send a replacement from the north warehouse if it has the item, else from south, else from east (check each in that order, and only as far as needed), and take the damaged item back with a return. If the return is refused, open a damage claim for the order with open_claim. Then reply to the customer with what you did, giving any reference numbers and the date the replacement ships.
- user
Hi, it's dee.holm@example.com. My kettle arrived with a cracked lid. Can you sort it out?
- assistant
lookup_account({"email":"dee.holm@example.com"}) - tool
{"account_id": "AC-630", "name": "Dee Holm"} - assistant
list_orders({"account_id":"AC-630"}) - tool
{"orders": [{"order_id": "R-5370", "placed": "2026-10-01", "status": "delivered"}, {"order_id": "R-5233", "placed": "2026-10-09", "status": "delivered"}, {"order_id": "R-5360", "placed": "2026-10-27", "status": "in transit"}]} - assistant
get_order({"order_id":"R-5370"}) - tool
{"items": [{"name": "Oak table lamp", "quantity": 1, "sku": "lamp-oak"}], "order_id": "R-5370"} - assistant
get_order({"order_id":"R-5233"}) - tool
{"items": [{"name": "Steel kettle", "quantity": 1, "sku": "kettle-steel"}, {"name": "Grey mug", "quantity": 2, "sku": "mug-grey"}], "order_id": "R-5233"} - assistant
check_stock({"sku":"kettle-steel","warehouse":"north"}) - tool
{"available": 0, "sku": "kettle-steel", "warehouse": "north"} - assistant
check_stock({"sku":"kettle-steel","warehouse":"south"}) - tool
{"available": 4, "sku": "kettle-steel", "warehouse": "south"} - assistant
create_return({"order_id":"R-5233","reason":"cracked lid"}) - tool
{"error": "damaged items are not returned: open a damage claim with open_claim instead"} - assistant
open_claim({"order_id":"R-5233","reason":"cracked lid"}) - tool
{"claim_id": "CL-1883", "order_id": "R-5233", "status": "open"} - assistant
reserve_item({"order_id":"R-5233","sku":"kettle-steel","warehouse":"south"}) - tool
{"reservation_id": "RS-4014", "ships_on": "2026-11-02"} - assistant
Hi Dee, I’ve taken care of the issue with your cracked kettle: - **Damage claim opened** – Claim ID **CL‑1883** for order **R‑5233** (the kettle). - **Replacement reserved** – A new steel kettle (SKU kettle‑steel) has been reserved from our **south** warehouse. - **Shipment date** – The replacement will ship on **2026‑11‑02** (Reservation ID RS‑4014). You’ll receive a confirmation email shortly with the claim details and tracking information once the item ships. If you have any further questions, just let me know!
- system
Comments
Sign in or create an account to comment.