Code RoomFloating point rounding loses cents
MediumPrep Room Coding #3999

Floating point rounding loses cents

Vibe & agenticAlgorithms & data structuresMid–Senior~15 min

An AI agent wrote this JavaScript helper to split a charge evenly across N parties and assert nothing is lost, for a payments feature:

It works for `splitAmount(100, 4)`. Why is this dangerous in production, and what's the right approach?

Implement
split_cents_evenly(total_cents: int, parties: int) → list[int]
Examples
in[10000,4]out[2500,2500,2500,2500]
in[10000,3]out[3334,3333,3333]
in[10,3]out[4,3,3]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 15 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.