{
"id": "258",
"prompt": "Conway's Game of Life on a 16x12 torus, one 16-bit row mask per state slot. Advance a generation every 8 frames: for each cell count the eight wrapped neighbors by testing bits of the row masks, then apply plain B3/S23 into a fresh local row array before writing back (never mutate in place mid-count). Seed a glider plus a blinker at init, show a GEN counter, and let a tap reroll the whole board from an LCG. Cells are fat 22px squares on a dim grid.",
"solution_rl": "fn frame(t: i32) {\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n let mut r: i32 = 0;\n while r < 12 {\n host::display::state_set(8 + r, 0);\n r = r + 1;\n }\n host::display::state_set(9, 4);\n host::display::state_set(10, 8);\n host::display::state_set(11, 14);\n host::display::state_set(15, 7168);\n host::display::state_set(2, 4441);\n host::display::state_set(4, 0);\n }\n let mut cur = [0; 12];\n let mut r: i32 = 0;\n while r < 12 {\n cur[r] = host::display::state_get(8 + r);\n r = r + 1;\n }\n let down: i32 = host::display::pointer_down();\n if down == 1 && host::display::state_get(3) == 0 {\n let mut seed: i32 = host::display::state_get(2);\n r = 0;\n while r < 12 {\n seed = seed * 1103515245 + 12345;\n cur[r] = (seed >> 8) & 65535;\n host::display::state_set(8 + r, cur[r]);\n r = r + 1;\n }\n host::display::state_set(2, seed);\n host::display::state_set(4, 0);\n }\n host::display::state_set(3, down);\n if t % 8 == 0 {\n let mut nxt = [0; 12];\n r = 0;\n while r < 12 {\n let mut newrow: i32 = 0;\n let mut c: i32 = 0;\n while c < 16 {\n let mut n: i32 = 0;\n let mut dr: i32 = 0;\n while dr < 3 {\n let mut dc: i32 = 0;\n while dc < 3 {\n if dr != 1 || dc != 1 {\n let rr: i32 = (r + dr + 11) % 12;\n let cc: i32 = (c + dc + 15) % 16;\n n = n + ((cur[rr] >> cc) & 1);\n }\n dc = dc + 1;\n }\n dr = dr + 1;\n }\n let alive: i32 = (cur[r] >> c) & 1;\n if n == 3 || (alive == 1 && n == 2) {\n newrow = newrow | (1 << c);\n }\n c = c + 1;\n }\n nxt[r] = newrow;\n r = r + 1;\n }\n r = 0;\n while r < 12 {\n cur[r] = nxt[r];\n host::display::state_set(8 + r, cur[r]);\n r = r + 1;\n }\n host::display::state_set(4, host::display::state_get(4) + 1);\n }\n host::display::clear(0x0a0a0a);\n r = 0;\n while r < 12 {\n let mut c: i32 = 0;\n while c < 16 {\n let col: i32 = if ((cur[r] >> c) & 1) == 1 { 0xd0ffd0 } else { 0x161816 };\n host::display::fill_rect(64 + c * 24, 100 + r * 24, 22, 22, col);\n c = c + 1;\n }\n r = r + 1;\n }\n host::display::draw_string(64, 40, \"GEN\", 0x707070, 2);\n host::display::draw_number(130, 40, host::display::state_get(4), 0xffffff, 2);\n host::display::draw_string(64, 70, \"TAP = RESEED\", 0x505050, 1);\n host::display::present();\n}\n",
"tags": [
"simulation",
"life",
"bitmask",
"state"
]
}