DEV Community

Discussion on: Daily Challenge #120 - Growth of a Population

Collapse
 
aminnairi profile image
Amin • Edited

Elm

overcrowding : Int -> Float -> Int -> Int -> Int
overcrowding population evolution augmentation expectedPopulation =
    let
        newPopulation : Int
        newPopulation =
            (toFloat population) * (1.0 + evolution / 100) ^ 1 + (toFloat augmentation)
                |> ceiling
    in
    if newPopulation > expectedPopulation then
        1

    else
        1 + overcrowding newPopulation evolution augmentation expectedPopulation

Playground

Ellie App.