DEV Community

Discussion on: Daily Challenge #69 - Going to the Cinema

Collapse
 
aminnairi profile image
Amin • Edited

Elm

module Movie exposing (movie)


getReduction : Int -> Float -> Float
getReduction times percentage =
    percentage ^ toFloat times


profitableNumberOfMovies : Int -> Int -> Float -> Int -> Int
profitableNumberOfMovies card ticket percentage times =
    let
        reduction : Float
        reduction =
            getReduction times percentage

        increasedCard : Int
        increasedCard =
            ceiling <| toFloat card + toFloat ticket * reduction

        increasedTicket : Int
        increasedTicket =
            ticket * times
    in
    if increasedCard < increasedTicket then
        times - 1

    else
        profitableNumberOfMovies increasedCard ticket percentage <| times + 1


movie : Int -> Int -> Float -> Int
movie card ticket percentage =
    profitableNumberOfMovies card ticket percentage 1

Tests

module MovieTest exposing (suite)

import Expect
import Movie exposing (movie)
import Test exposing (Test)


suite : Test
suite =
    Test.describe "Movie"
        [ Test.test "It should return 43 for movie 500 15 0.9" <|
            \_ ->
                Expect.equal 43 <| movie 500 15 0.9
        , Test.test "It should return 24 for movie 100 10 0.95" <|
            \_ ->
                Expect.equal 24 <| movie 100 10 0.95
        ]