{
"id": "194",
"prompt": "A waterfall chart of the deltas [40, -15, 25, -30, 20]: each bar floats at the running cumulative level (green for gains, red for losses) with a connector line carrying each level to the next bar, the signed delta printed above each bar (hand-draw the minus with draw_char - draw_number has no sign), and a white TOTAL bar at the end.",
"solution_rl": "fn draw_signed(x: i32, y: i32, v: i32, rgb: i32, sc: i32) {\n if v < 0 {\n host::display::draw_char(x, y, 45, rgb, sc);\n host::display::draw_number(x + sc * 8, y, 0 - v, rgb, sc);\n } else {\n host::display::draw_number(x, y, v, rgb, sc);\n }\n}\n\nfn frame(t: i32) {\n let w: i32 = host::display::width();\n let h: i32 = host::display::height();\n host::display::clear(0x0c0c0c);\n let base: i32 = h - 60;\n let deltas = [40, -15, 25, -30, 20];\n let bw: i32 = (w - 40) / 6;\n let mut c: i32 = 0;\n let mut i: i32 = 0;\n while i < 5 {\n let d: i32 = deltas[i];\n let n: i32 = c + d;\n let top: i32 = if d > 0 { n } else { c };\n let bh: i32 = if d > 0 { d } else { 0 - d };\n let col: i32 = if d > 0 { 0x30c060 } else { 0xd04040 };\n let x: i32 = 20 + i * bw;\n host::display::fill_rect(x + 4, base - top * 3, bw - 8, bh * 3, col);\n draw_signed(x + 4, base - top * 3 - 14, d, 0xc0c0c0, 1);\n host::display::draw_line(x + bw - 4, base - n * 3, x + bw + 4, base - n * 3, 0x808080);\n c = n;\n i = i + 1;\n }\n host::display::fill_rect(20 + 5 * bw + 4, base - c * 3, bw - 8, c * 3, 0xffffff);\n host::display::draw_string(20 + 5 * bw, base + 10, \"TOTAL\", 0x808080, 1);\n host::display::draw_number(20 + 5 * bw + 4, base - c * 3 - 14, c, 0xffffff, 1);\n host::display::draw_line(16, base, w - 16, base, 0x606060);\n host::display::present();\n}\n",
"tags": [
"chart",
"arrays",
"math"
]
}