module Exercise05 where import Data.List -- 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 |0 `elem`ds =[] | otherwise = decompose2 ds (biggest ds) 0 decompose2 ::[Integer]->Integer->Integer->[Integer] decompose2 ds y x |y==1 =[biggest2 ds y-x] |otherwise = decompose2 ds (y`div`2) (b*2^length ds)++[b-x] where b =biggest2 ds y biggest ::[Integer]->Integer biggest ds= 2^minimum [log2 y| y<-ds] biggest2 ::[Integer]->Integer->Integer biggest2 ds x =product [y `div` x| y<-ds] {-TTEW-}