When nothing can go
Why it matters Subtraction is a strong habit, and a strong habit misfires. Some code is exactly as long as the problem, and every line is load-bearing.
Support agents can refund a card charge. The payments team gives four rules:
- The refund amount is more than zero.
- The refund currency matches the charge currency.
- All refunds on the charge, including this one, add up to no more than the charge.
- The refund is made within 180 days of the charge date (day 180 is fine, day 181 is not).
A colleague suggests dropping the sum of earlier refunds in rule 3, "because the payment provider would refuse an over-refund anyway". Another suggests a small rule engine so new rules can be registered without touching the function. Decide for yourself which, if either, is right.
Write refund_ok(charge, earlier, cents, currency, today): charge is a dict with "cents", "currency" and "date" (a date); earlier is a list of cents already refunded on it; cents and currency describe the new refund; today is a date. Return True only if all four rules hold. Rule: your whole code may have at most 90 syntax nodes (code_size).
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.