7 kyu

Going to the cinema

292 of 12,393g964

Description:

My friend John likes to go to the cinema. He can choose between system A and system B.

System A : he buys a ticket (15 dollars) every time
System B : he buys a card (500 dollars) and a first ticket for 0.90 times the ticket price, 
then for each additional ticket he pays 0.90 times the price paid for the previous ticket.

Example:

If John goes to the cinema 3 times:

System A : 15 * 3 = 45
System B : 500 + 15 * 0.90 + (15 * 0.90) * 0.90 + (15 * 0.90 * 0.90) * 0.90 ( = 536.5849999999999, no rounding for each ticket)

John wants to know how many times he must go to the cinema so that the final result of System B, when rounded up to the next dollar, will be cheaper than System A.

The function movie has 3 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 System B) < price of System A.

More examples:

movie(500, 15, 0.9) should return 43 
    (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)
Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedOct 27, 2015
PublishedOct 27, 2015
Warriors Trained36703
Total Skips4689
Total Code Submissions133864
Total Times Completed12393
Ruby Completions292
Python Completions2539
JavaScript Completions3321
Haskell Completions108
Java Completions1349
C# Completions557
Clojure Completions71
CoffeeScript Completions17
C++ Completions755
Elixir Completions145
TypeScript Completions260
PHP Completions436
Crystal Completions14
F# Completions54
C Completions485
Shell Completions91
OCaml Completions45
Kotlin Completions453
Fortran Completions27
Scala Completions166
Julia Completions28
R Completions124
PowerShell Completions93
Go Completions473
Nim Completions18
Rust Completions274
Reason Completions9
Racket Completions30
Forth Completions13
Dart Completions259
Haxe Completions14
Swift Completions419
Pascal Completions34
Lua Completions97
Perl Completions34
Elm Completions9
D Completions10
Erlang Completions18
Prolog Completions12
Total Stars502
% of votes with a positive feedback rating80% of 1843
Total "Very Satisfied" Votes1296
Total "Somewhat Satisfied" Votes373
Total "Not Satisfied" Votes174
Ad
Contributors
  • g964 Avatar
  • joh_pot Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Wouter125 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad