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 = if containsZero ds then [] else decomposeHelper ds 0 maxDim (toInteger (length ds)) where maxDim = toInteger (length (bin (minimum ds)) - 1) containsZero :: [Integer] -> Bool containsZero [] = False containsZero (x:xs) | x == 0 = True | otherwise = containsZero xs --Übersetzt input int in binär darstellung bin :: Integer -> [Integer] bin 0 = [] bin int = (int `mod` 2) : bin (int `div` 2) decomposeHelper :: [Integer] -> Integer -> Integer -> Integer -> [Integer] -- input - preVol - current Dimension - Dimension decomposeHelper xs vol 0 _ = [x] where x = product (ggV xs 1) - vol decomposeHelper xs vol currDim maxDim = decomposeHelper xs (vol + x * (2^(currDim * maxDim))) (currDim - 1) maxDim ++ [x] where x = (product (ggV xs (2^currDim)) - vol) `div` (2^(currDim * maxDim)) ggV :: [Integer] -> Integer -> [Integer] -- berechnet den größte zweier potenz welches x element von xs teilt ggV [] _ = [] ggV (x:xs) num = (x `div` num) * num : ggV xs num {-TTEW-}