Today's problem is an easy but useful one. Given a list of bills, print out how much each roommate owes. There will exist some cases where your currency does not support the denomination when split. In that case one roommate will have to pay more than another. For example:
bill_split(2, [11, 15, 11.01]) 18.50 18.51
Comments:
Andreas - 10 years, 4 months ago
done in Scala (there is probably a shorter way, but this is what I came up with first)
reply permalink
Nick Krichevsky - 10 years, 4 months ago
reply permalink
bumbleguppy - 10 years, 4 months ago
This was one of those seems-simple-enough-OH-MY-GOD-WHAT'S-HAPPENING problems. Floating point numbers are craaaaaaaazy, at least in javascript. Also, I didn't feel right dumping the remainder on one payer if there were more than 2 people and the remainder was more than 1.
reply permalink