Created
November 5, 2021 08:10
-
-
Save kowasaur/7c214080193936a241c3cda56cb335a1 to your computer and use it in GitHub Desktop.
Thing I made for my specialist maths homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Used to solve specialist homework question | |
-- Constants | |
breedingRates = [ 0, 1.3, 1.8, 0.9, 0.2] | |
survivalRates = [0.6, 0.8, 0.8, 0.4, 0] | |
initialPopulations = [194, 82, 55, 22, 6] | |
-- Population after n years | |
populations 0 = initialPopulations | |
-- The takeWhile is unnecessary but I added it in case the last survival rate isn't 0 | |
populations n = takeWhile (>0) $ sum (zipWith (*) (populations (n-1)) breedingRates) : zipWith (*) (populations (n-1)) survivalRates | |
wholePopulations n = map floor $ populations n | |
totalPopulation n = sum $ populations n | |
totalWholePopulation n = floor $ totalPopulation n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment