Last active
October 1, 2015 12:35
-
-
Save Show-vars/50784cdd6396cbbebe5b to your computer and use it in GitHub Desktop.
homework.hs
This file contains hidden or 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
-- factorial number | |
factorial 0 = 1 | |
factorial n = n * factorial (n - 1) | |
-- factorial each element | |
factorialEach [] = [] | |
factorialEach (y:yx) = factorial y : factorialEach yx | |
-- multiply each element by x | |
productEachByN x [] = [] | |
productEachByN x (y:yx) = (y * x) : productEachByN x yx | |
-- multiplys all elements | |
productEach [] = 1 | |
productEach (y:yx) = y * product yx | |
-- summ all elements | |
groupSumm [] = 0 | |
groupSumm (y:yx) = y + groupSumm yx | |
-- maximum element in list | |
maximumXs x [] = x | |
maximumXs x (y:yx) | |
| x < y = maximumXs y yx | |
| otherwise = maximumXs x yx | |
maximumEach [] = 0 | |
maximumEach xs = maximumXs 0 xs | |
main = do | |
print(productEachByN 2 [1,2,3,4,5,6,7]) | |
print(productEach [1,2,3]) | |
print(groupSumm [1,2,3,4,5]) | |
print(factorialEach [1,2,3,4,5]) | |
print(maximumEach [1,2,6,4,5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment