Advertisement
PifyZ

Lundi 9

Feb 9th, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Box = Box {
  2.     x :: Int,
  3.     y :: Int,
  4.     z :: Int
  5. } deriving (Show, Ord, Eq)
  6.  
  7. type ListBoxes = [Box]
  8.  
  9. -- inputBoxes :: ListBoxes
  10. inputBoxes = [
  11.     Box 3 3 3,
  12.     Box 2 2 2,
  13.     Box 2 2 2,
  14.     Box 4 4 4,
  15.     Box 1 1 1,
  16.     Box 1 1 1,
  17.     Box 1 1 1,
  18.     Box 1 1 1,
  19.     Box 1 1 1,
  20.     Box 1 1 1,
  21.     Box 1 1 1]
  22.  
  23. -- sizeBox :: Box -> Int
  24. sizeBox b = x b * y b * z b
  25.  
  26. sizeBoxes [] = 1
  27. sizeBoxes (box:xs) =
  28.     x box * y box * z box + sizeBoxes xs
  29.  
  30. -- splitBoxes :: ListBoxes -> (Box, ListBoxes)
  31. splitBoxes (bigBox:boxes) = (bigBox, boxes)
  32.  
  33. -- bigBox :: Box
  34. -- boxes :: ListBoxes
  35. (bigBox, boxes) = splitBoxes inputBoxes
  36.  
  37. combinations :: Int -> [a] -> [[a]]
  38. combinations k xs = combinations' (length xs) k xs
  39.     where combinations' n k' l@(y:ys)
  40.         | k' == 0   = [[]]
  41.         | k' >= n   = [l]
  42.         | null l    = []
  43.         | otherwise = map (y :) (combinations' (n - 1) (k' - 1) ys) ++ combinations' (n - 1) k' ys
  44.  
  45. combinationsRecursive' :: ListBoxes -> Int -> [ListBoxes]
  46. combinationsRecursive' boxes 0 = []
  47. combinationsRecursive' boxes len =
  48.     combinations len boxes  ++ combinationsRecursive' boxes (len - 1)
  49.  
  50. combinationsRecursive :: ListBoxes -> [ListBoxes]
  51. combinationsRecursive boxes =
  52.     combinationsRecursive' boxes (length boxes)
  53.  
  54. a = combinationsRecursive boxes
  55.  
  56. sizes' [] accum = accum
  57. sizes' (listBoxes:xs) accum = sizes' xs $ accum ++ [sizeBoxes listBoxes]
  58.  
  59. sizes boxes = sizes' boxes []
  60.  
  61. printSizes [] = do print "end"
  62. printSizes (size:xs) = do
  63.     print size
  64.     printSizes xs
  65.  
  66. maxSizes' [] accum = accum
  67. maxSizes' (size:xs) accum =
  68.     if size <= sizeBox bigBox then
  69.         maxSizes' xs (accum ++ [size])
  70.     else
  71.         maxSizes' xs accum
  72.  
  73. maxSizes sizes = maxSizes' sizes []
  74.  
  75. sizesa = sizes a
  76.  
  77. -- main :: IO ()
  78. main = do
  79.     print $ sizeBox bigBox
  80.     -- print $ sizeBoxes boxes
  81.     print $ maxSizes sizesa
  82.     -- getLine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement