{
"id": "189",
"prompt": "A BCD binary clock running off t at 60 fps, seeded at 23:59:30 so the midnight rollover shows quickly: six columns (tens and units of H, M, S) of square dot-lights with the least-significant bit at the bottom, 2/4/3/4/3/4 bits per column, lit dots cyan and unlit ones hollow outlines. Always parenthesize the bit test: ((v >> b) & 1) == 1.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n let total: i32 = t / 60 + 23 * 3600 + 59 * 60 + 30;\n let hh: i32 = (total / 3600) % 24;\n let mm: i32 = (total / 60) % 60;\n let ss: i32 = total % 60;\n let vals = [hh / 10, hh % 10, mm / 10, mm % 10, ss / 10, ss % 10];\n let bits = [2, 4, 3, 4, 3, 4];\n host::display::clear(0x06060a);\n let colw: i32 = w / 8;\n let cell: i32 = 44;\n let y0: i32 = h / 2 + 60;\n let mut c: i32 = 0;\n while c < 6 {\n let x: i32 = colw / 2 + c * colw + (c / 2) * colw / 2;\n let v: i32 = vals[c];\n let mut b: i32 = 0;\n while b < bits[c] {\n let y: i32 = y0 - b * cell;\n if ((v >> b) & 1) == 1 {\n host::display::fill_rect(x, y, 24, 24, 0x00e0d0);\n } else {\n host::display::fill_rect(x, y, 24, 24, 0x242430);\n host::display::fill_rect(x + 2, y + 2, 20, 20, 0x06060a);\n }\n b = b + 1;\n }\n host::display::draw_number(x + 6, y0 + cell, v, 0x808080, 2);\n c = c + 1;\n }\n host::display::draw_string(colw / 2, h - 24, \"H H M M S S\", 0x606060, 1);\n host::display::present();\n}\n",
"tags": [
"time",
"bitmask",
"arrays"
]
}