{
"id": "023",
"prompt": "Histogram with array WRITES: start from `let mut bins = [0; 8];`, run 64 iterations of the LCG hash h = (h * 1103515245 + 12345), bump bins[(h >> 16) & 7] each round, then draw the 8 bin counts as bars. Arrays are per-frame locals, which is fine here since it is recomputed every frame.",
"solution_rl": "fn frame(t: i32) {\n let mut bins = [0; 8];\n let mut h: i32 = 7;\n let mut i: i32 = 0;\n while i < 64 {\n h = h * 1103515245 + 12345;\n let idx: i32 = (h >> 16) & 7;\n bins[idx] = bins[idx] + 1;\n i = i + 1;\n }\n let w: i32 = host::display::width();\n let hh: i32 = host::display::height();\n host::display::clear(0x000000);\n let bw: i32 = w / 8;\n let mut k: i32 = 0;\n while k < 8 {\n host::display::fill_rect(k * bw + 2, hh - bins[k] * 8 - 4, bw - 4, bins[k] * 8, 0xffaa00);\n k = k + 1;\n }\n host::display::present();\n}\n",
"tags": [
"arrays",
"prng",
"loops"
]
}