module Exercise_8 where import Data.List {-WETT-} shoefa :: (Num a, Ord a) => [a] -> Int shoefa xs = if null f then 0 else pred $ length $ group $ map signum f where f = filter (/=0) xs -- shoefa xs = length $ groupBy (<) $ map signum $ filter (/=0) xs -- shoefaTest xs = groupBy (<) $ map signum $ filter (/=0) xs -- Token -- shoefa [] = 0 -- shoefa xs = fst $ foldl (\acc s -> if snd acc == s then acc else (1+fst acc, snd acc) ) (0,head nums) nums -- where -- nums = [signum x |x <- xs, 0 /= signum x] -- Token -- shoefa [] = 0 -- shoefa xs = fst $ foldl (\(i,p) s -> if p == s then (i,p) else (i+1, s) ) (0,head nums) nums -- where -- nums = [signum x |x <- xs, 0 /= signum x] -- Token -- shoefa [] = 0 -- shoefa xs = shoefaRec nums $signum $head nums -- where -- nums = [signum x |x <- xs, 0 /= signum x] -- shoefaRec [] _ = 0 -- shoefaRec (x:xs) prev = if (prev == x) -- then 0 + shoefaRec xs prev -- else 1 + shoefaRec xs x -- Case [0,1] fail -- shoefa [] = 0 -- shoefa xs = shoefaRec xs $signum $head xs -- where -- shoefaRec [] _ = 0 -- shoefaRec (x:xs) prev = if prev == signum x || 0 == signum x -- then 0 + shoefaRec xs prev -- else 1 + shoefaRec xs prev {-TTEW-}