module Exercise05 where import Data.Bits ( Bits(shiftL, shiftR) ) -- 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 [] = [] decompose ds = decomposeRec ds (product ds) (length ds) decomposeRec :: [Integer] -> Integer -> Int -> [Integer] decomposeRec _ 0 _ = [] decomposeRec ds size dim = (size - shiftL newsize dim) : decomposeRec inner newsize dim where newsize = product inner inner = map ( `shiftR` 1) ds {-TTEW-}