Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import Data.Function
  2. import Data.List
  3.  
  4. combinations :: Int -> [a] -> [[a]]
  5. combinations 0 _ = [ [] ]
  6. combinations n xs = [ y:ys | y:xs' <- tails xs
  7. , ys <- combinations (n-1) xs']
  8.  
  9.  
  10. names = ["clock", "painting", "radio", "vase", "book", "computer"]
  11. vals = [175, 90, 20, 50, 10, 200]
  12. weights = [10, 9, 4, 2, 1, 20]
  13.  
  14. goods = [(names !! i,vals !! i,weights !! i) | i<-[0..5]]
  15.  
  16. combs = foldl1 (++) [combinations i goods | i<-[1..6]]
  17.  
  18. less = filter (\xs -> sum [w|(_,_,w)<-xs] <= 20) combs
  19.  
  20. ans = maximumBy (on compare (\r -> sum [v|(_,v,_)<-r])) less
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement