module Exercise05 where import Data.List (sort) -- 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-} -- Try fit Block in the space size by size fitBlocks :: [Integer] -> Integer -> Integer -> [Integer] fitBlocks ds _ 0 = [product ds] fitBlocks ds factor cubeIndex = result : smaller - (result * factor) : above -- remove space for bigger squares where bigCube = 2 ^ cubeIndex cubeNumbers = [x `quot` bigCube | x <- ds] result = product cubeNumbers (smaller : above) = fitBlocks ds factor (cubeIndex -1) -- helper for fitBlocks decomposeE :: [Integer] -> [Integer] decomposeE (0 : _) = [] -- flat? decomposeE ds@(minLength : _) = reverse result where dimentions = length ds minIndex = log2 minLength result = fitBlocks ds (2 ^ dimentions) minIndex decompose :: [Integer] -> [Integer] decompose ds = decomposeE (sort ds) {-TTEW-}