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
| sum' :: (Num a) => [a] -> a | |
| sum' xs = foldl (\acc x -> acc + x) 0 xs | |
| sum'' :: (Num a) => [a] -> a | |
| sum'' = foldl (+) 0 | |
| map' :: (a -> b) -> [a] -> [b] | |
| map' f xs = foldr (\x acc -> f x : acc) [] xs | |
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
| chain :: Integer -> [Integer] | |
| chain 1 = [1] | |
| chain n | |
| | even n = n : chain (n `div` 2) | |
| | odd n = n : chain (n * 3 + 1) | |
| numLongChains :: Int | |
| numLongChains = length (filter (\xs -> length xs > 15) (map chain [1..100])) | |
| flip' :: (a -> b -> c) -> b -> a -> c |
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
| quicksort :: (Ord a) => [a] -> [a] | |
| quicksort [] = [] | |
| quicksort (x:xs) = | |
| let smallOrEqual = filter (<= x) xs | |
| larger = filter (> x) xs | |
| in quicksort smallOrEqual ++ [x] ++ quicksort larger | |
| largestDivisible :: [Int] -> Bool | |
| largestDivisible [] = False | |
| largestDivisible (x:xs) |
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
| largestDivisible :: [Int] -> Bool | |
| largestDivisible [] = False | |
| largestDivisible (x:xs) | |
| | (x `mod` 3829) == 0 = True | |
| | otherwise = largestDivisible xs |
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
| zip' :: [a] ->[b] -> [(a,b)] | |
| zip' _ [] = [] | |
| zip' [] _ = [] | |
| zip' (x:xs) (y:ys) = (x,y) : zip' xs ys | |
| elem' :: (Eq a) => a -> [a] -> Bool | |
| elem' a [] = False | |
| elem' a (x:xs) | |
| | a == x = True |
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
| replicate' :: Int -> a -> [a] | |
| replicate' n x | |
| | n <= 0 = [] | |
| | otherwise = x : (replicate' (n-1) x) | |
| maximum' :: (Ord a) => [a] -> a | |
| maximum' xs = case xs of [] -> error "maximum of empty list" | |
| [x] -> x | |
| (x:xs) -> max x (maximum' xs) |
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
| replicate' :: Int -> a -> [a] | |
| replicate' n x | |
| | n <= 0 = [] | |
| | otherwise = x : (replicate' (n-1) x) | |
| maximum' :: (Ord a) => [a] -> a | |
| maximum' xs = case xs of [] -> error "maximum of empty list" | |
| [x] -> x | |
| (x:xs) -> max x (maximum' xs) |
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
| head' :: [a] -> a | |
| head' [] = error "No Head" | |
| head' (x:_) = x | |
| head2' :: [a] -> a | |
| head2' xs = case xs of [] -> error "No Head" | |
| (x:_) -> x | |
| describeList :: [a] -> String | |
| describeList ls = "This list is" ++ case ls of [] -> " empty" |
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
| calcBmis :: [(Double, Double)] -> [Double] | |
| calcBmis xs = [ bmi | (w,h) <- xs, let bmi = w / h ^ 2, bmi > 30.0] |
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
| squareList :: [Int] -> [Int] | |
| squareList xs = [ square' | x <- xs, let square' = x ^ 2] |