Daily Challenge (97 Part Series)
Today's challenge is to help John make an important financial decision!
John likes to go to the cinema, but he wants to find the most cost-effective way to go. He can buy a ticket for $15, or he can buy a membership card for $500. Every time he uses the membership card, the ticket will be 0.9 times the price he paid for the last one.
Ex. If John goes to the cinema three times:
A : 15 * 3 = 45
B : 500 + 15 * 0.90 + (15 * 0.90) * 0.90 + (15 * 0.90 * 0.90) * 0.90 ( = 536.5849999999999, no rounding for each ticket)
Create a function
movie with three parameters:
card (price of the card),
ticket(normal price of a ticket),
perc(fraction of what he paid for the previous ticket) and returns the first
n such that
ceil(price of B) < price of A
movie(500, 15, 0.9)should return
(with card the total price is 634, with tickets 645)
movie(100, 10, 0.95) should return
(with card the total price is 235, with tickets 240)
Want to propose a challenge idea for a future post? Email firstname.lastname@example.org with your suggestions!