Daily Challenge #69 - Going to the Cinema
dev.to staff
Posted on September 17, 2019
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
More examples:
movie(500, 15, 0.9)
should return43
(with card the total price is 634, with tickets 645)
movie(100, 10, 0.95)
should return 24
(with card the total price is 235, with tickets 240)
Good luck!
Today's challenge comes from CodeWars user g964. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Posted on September 17, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.