module Exercise05 where -- May or may not be useful: computes the logarithm base 2 (rounded down) of the given number. -- You don't have to move this into the WETT tags if you want to use it. log2 :: (Integral a, Num b) => a -> b log2 = let go acc n = if n <= 1 then acc else go (acc + 1) (n `div` 2) in go 0 {-WETT-} decompose :: [Integer] -> [Integer] decompose ds | 0 `elem` ds = [] | otherwise = decomposeR [] ds 1 [] 0 decomposeR :: [Integer] -> [Integer] -> Integer -> [Integer] -> Integer -> [Integer] decomposeR ls [] i xs x = decomposeR [] (map (`div` 2) ls) (i*2) (xs ++ [x]) 0 decomposeR ls (m:rs) i xs x | even m = decomposeR (m:ls) rs i xs x | m == 1 = xs ++ [x + (product ls * product rs)] | otherwise = decomposeR ((m-1):ls) rs i xs (x + (product ls * product rs)) {-TTEW-}