Skip to content

Instantly share code, notes, and snippets.

View alexander-makarov's full-sized avatar

Alexander Makarov alexander-makarov

View GitHub Profile
--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) =
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