module Exercise05 where import Data.List (product) import Data.List (minimum) -- 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 | product ds == 0 = [] | otherwise = helpDecompose ds 0 (log2 (minimum ds)) (length ds) helpDecompose :: [Integer] -> Integer -> Integer -> Int -> [Integer] helpDecompose ds sum exponent dimension | exponent == 0 = [(product ds - sum) `div` 1] | otherwise = helpDecompose ds (sum + x*((2^exponent)^dimension)) (exponent-1) dimension ++ [((getProdukt ds (2^exponent)) - sum) `div` ((2^exponent)^dimension)] where x = ((getProdukt ds (2^exponent)) - sum) `div` ((2^exponent)^dimension) getProdukt :: [Integer] -> Integer -> Integer getProdukt ds number = product [(x `div` number)*number | x <- ds] {-TTEW-}