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 = reverse $ rmLeadingZeors $ process [ product (map (`div` 2^i) ds) | i <- [pwr, pwr -1 .. 0]] 0 dim where dim = length ds pwr = minimum $ map log2 ds process :: (Integral t, Num a) => [a] -> a -> t -> [a] process [] _ _ = [] process (x:xs) acc dim = x-acc:process xs ((acc + (x-acc))*(2^dim)) dim rmLeadingZeors :: (Eq a, Num a) => [a] -> [a] rmLeadingZeors (0:xs) = rmLeadingZeors xs rmLeadingZeors xs = xs {-TTEW-}