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 | m == 0 = [] | otherwise = cnt:(decompose (map (`div` 2) ds)) where m = product ds calc :: [Integer] -> Integer -> Integer calc [] _ = 0 calc _ 0= 0 calc (x:xs) k | mod x 2 == 0 = calc xs k | otherwise = (div k x) + (calc xs ((x-1) * (div k x))) cnt = calc ds m {-TTEW-}