Solution in Haskell:
import Data.List (find) calcMean :: [Double] -> Double calcMean [] = -1 calcMean xs = (foldr (+) 0 xs) / (fromIntegral . length $ xs) calcVar :: [Double] -> Double calcVar [] = -1 calcVar xs = calcMean . fmap diff $ xs where diff x = (x - calcMean xs)^2 getValues :: String -> String -> [Double] getValues town = maybe [] parse . find theTown . lines where theTown = (==town) . takeWhile (/=':') parse = fmap (read . takeWhile (/=',')) . tail . words mean :: String -> String -> Double mean town = calcMean . getValues town variance :: String -> String -> Double variance town = calcVar . getValues town
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution in Haskell: