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
--import Control.Monad.Error | |
data Tree = Leaf | Node Int Tree Tree deriving Show | |
getSortedTreeExample = Node 5 (Node 2 Leaf (Node 4 Leaf Leaf)) (Node 13 (Node 8 Leaf (Node 11 Leaf Leaf)) Leaf) | |
getTreeExample = Node 5 (Node 2 Leaf (Node 4 Leaf Leaf)) (Node 13 (Node 8 (Node 11 Leaf Leaf) Leaf) Leaf) | |
treeDepth :: Tree -> Int | |
treeDepth Leaf = 0 | |
treeDepth (Node _ leftSubtree rightSubtree) = |
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
import Data.Char | |
sumCows :: (Eq a, Num b) => [a] -> [a] -> b | |
sumCows [] _ = 0 | |
sumCows _ [] = 0 | |
sumCows (x:xs) (y:ys) = (if (x /= y) && (elem y xs) then 1 else 0) + sumCows (xs++[x]) ys | |
capitalize :: String -> String | |
capitalize = map toUpper |