Created
January 7, 2019 02:18
-
-
Save bolerap/a0a865416ac71578faf82239b88d7bce to your computer and use it in GitHub Desktop.
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
-- Simple.hs | |
-- calculates the summary of a sequence number with a pattern | |
-- eg: [1, 2, 3, 4] or [1, 3, 5, 7] or [1, 3, 6, 9] | |
-- general form [a..b] => sum = ((a + b) * length [a..b]) / 2 | |
seqSum :: Fractional a => [a] -> a | |
seqSum list = ((first + last) * len) / 2 | |
where | |
len = length list | |
first = head list | |
last = list !! (len - 1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
got error