{
"id": "276",
"prompt": "Classify an HTTP response: GET a page that probably 404s, and once ready(h) == 1 push status(h) through a match with ranges - 200..=299 OK (green), 300..400 REDIRECT (amber), 400..=499 CLIENT ERROR (red), wildcard SERVER ERROR (purple) - into a colored verdict card under the raw code drawn huge. A negative ready() means there is no upstream status at all; give that its own FETCH DENIED face.",
"solution_rl": "fn band_of(code: i32) -> i32 {\n match code {\n 200..=299 => 0,\n 300..400 => 1,\n 400..=499 => 2,\n _ => 3,\n }\n}\n\nfn frame(t: i32) {\n host::display::clear(0x0c0c10);\n if host::display::state_get(0) == 0 {\n let h: i32 = host::http::get(\"https://example.com/missing-page\", 32);\n host::display::state_set(1, h);\n if h < 0 {\n host::display::state_set(0, 3);\n } else {\n host::display::state_set(0, 1);\n }\n }\n let h2: i32 = host::display::state_get(1);\n if host::display::state_get(0) == 1 {\n let r: i32 = host::http::ready(h2);\n if r == 1 {\n host::display::state_set(0, 2);\n } else if r < 0 {\n host::display::state_set(0, 3);\n }\n }\n let phase: i32 = host::display::state_get(0);\n host::display::draw_string(90, 60, \"STATUS CLASSIFIER\", 0xffffff, 2);\n if phase == 1 {\n host::display::draw_string(190, 240, \"WAITING\", 0xaa7700, 2);\n } else if phase == 2 {\n let code: i32 = host::http::status(h2);\n let band: i32 = band_of(code);\n host::display::draw_number(180, 150, code, 0xffffff, 6);\n if band == 0 {\n host::display::fill_rect(150, 260, 212, 60, 0x1a5c2a);\n host::display::draw_string(220, 280, \"OK\", 0x66ff99, 3);\n } else if band == 1 {\n host::display::fill_rect(150, 260, 212, 60, 0x6b5416);\n host::display::draw_string(184, 280, \"REDIRECT\", 0xffcc44, 2);\n } else if band == 2 {\n host::display::fill_rect(150, 260, 212, 60, 0x5c1a1a);\n host::display::draw_string(160, 280, \"CLIENT ERROR\", 0xff8877, 2);\n } else {\n host::display::fill_rect(150, 260, 212, 60, 0x3a1a5c);\n host::display::draw_string(160, 280, \"SERVER ERROR\", 0xcc99ff, 2);\n }\n } else {\n host::display::draw_string(130, 240, \"FETCH DENIED\", 0xbb3333, 2);\n host::display::draw_string(96, 280, \"NO UPSTREAM STATUS TO CLASSIFY\", 0x777777, 1);\n }\n host::display::present();\n}\n",
"tags": [
"http",
"match",
"ranges"
]
}