{
"id": "245",
"prompt": "Simulate a shop checkout: every 20 frames a customer arrives with 55% probability (LCG roll, seed in a state slot) and joins the queue, capped at 22. One cashier always works - serving takes 45 frames per customer, tracked by a countdown slot that bumps the SERVED counter when it hits zero. Holding the pointer opens a second register with its own countdown that only ticks while held. Draw the queue as a row of little people, both desks, and the served total.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, 3);\n host::display::state_set(3, 77);\n }\n let mut q: i32 = host::display::state_get(1);\n let mut served: i32 = host::display::state_get(2);\n let mut ta: i32 = host::display::state_get(4);\n let mut tb: i32 = host::display::state_get(5);\n if t % 20 == 0 {\n let seed: i32 = host::display::state_get(3) * 1103515245 + 12345;\n host::display::state_set(3, seed);\n if ((seed >> 16) & 4095) % 100 < 55 && q < 22 {\n q = q + 1;\n }\n }\n if ta > 0 {\n ta = ta - 1;\n if ta == 0 { served = served + 1; }\n } else if q > 0 {\n q = q - 1;\n ta = 45;\n }\n let open: bool = host::display::pointer_down() == 1;\n if open {\n if tb > 0 {\n tb = tb - 1;\n if tb == 0 { served = served + 1; }\n } else if q > 0 {\n q = q - 1;\n tb = 45;\n }\n }\n host::display::state_set(1, q);\n host::display::state_set(2, served);\n host::display::state_set(4, ta);\n host::display::state_set(5, tb);\n host::display::clear(0x101014);\n host::display::fill_rect(40, 100, 60, 40, 0x306040);\n if ta > 0 { host::display::fill_rect(50, 70, 16, 20, 0xd0b080); }\n host::display::fill_rect(40, 180, 60, 40, if open { 0x306040 } else { 0x282828 });\n if tb > 0 { host::display::fill_rect(50, 150, 16, 20, 0xd0b080); }\n let mut i: i32 = 0;\n while i < q {\n host::display::fill_rect(130 + i * 15, 110, 10, 18, 0x8090a0);\n i = i + 1;\n }\n host::display::draw_string(40, 30, \"SERVED\", 0x808080, 2);\n host::display::draw_number(140, 30, served, 0xffffff, 2);\n host::display::draw_string(40, h - 40, \"HOLD = OPEN 2ND REGISTER\", 0x606060, 1);\n host::display::present();\n}\n",
"tags": [
"simulation",
"queue",
"prng",
"state"
]
}