Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Box = Box {
- x :: Int,
- y :: Int,
- z :: Int
- } deriving (Show, Ord, Eq)
- type ListBoxes = [Box]
- -- inputBoxes :: ListBoxes
- inputBoxes = [
- Box 3 3 3,
- Box 2 2 2,
- Box 2 2 2,
- Box 4 4 4,
- Box 1 1 1,
- Box 1 1 1,
- Box 1 1 1,
- Box 1 1 1,
- Box 1 1 1,
- Box 1 1 1,
- Box 1 1 1]
- -- sizeBox :: Box -> Int
- sizeBox b = x b * y b * z b
- sizeBoxes [] = 1
- sizeBoxes (box:xs) =
- x box * y box * z box + sizeBoxes xs
- -- splitBoxes :: ListBoxes -> (Box, ListBoxes)
- splitBoxes (bigBox:boxes) = (bigBox, boxes)
- -- bigBox :: Box
- -- boxes :: ListBoxes
- (bigBox, boxes) = splitBoxes inputBoxes
- combinations :: Int -> [a] -> [[a]]
- combinations k xs = combinations' (length xs) k xs
- where combinations' n k' l@(y:ys)
- | k' == 0 = [[]]
- | k' >= n = [l]
- | null l = []
- | otherwise = map (y :) (combinations' (n - 1) (k' - 1) ys) ++ combinations' (n - 1) k' ys
- combinationsRecursive' :: ListBoxes -> Int -> [ListBoxes]
- combinationsRecursive' boxes 0 = []
- combinationsRecursive' boxes len =
- combinations len boxes ++ combinationsRecursive' boxes (len - 1)
- combinationsRecursive :: ListBoxes -> [ListBoxes]
- combinationsRecursive boxes =
- combinationsRecursive' boxes (length boxes)
- a = combinationsRecursive boxes
- sizes' [] accum = accum
- sizes' (listBoxes:xs) accum = sizes' xs $ accum ++ [sizeBoxes listBoxes]
- sizes boxes = sizes' boxes []
- printSizes [] = do print "end"
- printSizes (size:xs) = do
- print size
- printSizes xs
- maxSizes' [] accum = accum
- maxSizes' (size:xs) accum =
- if size <= sizeBox bigBox then
- maxSizes' xs (accum ++ [size])
- else
- maxSizes' xs accum
- maxSizes sizes = maxSizes' sizes []
- sizesa = sizes a
- -- main :: IO ()
- main = do
- print $ sizeBox bigBox
- -- print $ sizeBoxes boxes
- print $ maxSizes sizesa
- -- getLine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement