Guest User

Untitled

a guest
Apr 21st, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2. import Data.Function (on)
  3. import Data.List (sortBy)
  4.  
  5. -- intial data type.
  6. data KSItem = Object {itemmo :: Int
  7.                         , weight :: Float
  8.                         , profit :: Float
  9.                         , itemname :: [Char]
  10.                         } deriving (Show, Eq, Ord)
  11.                                                
  12. -- Function for turning intital data type into advanced data type.
  13. devise :: KSItem -> FinKSItem
  14. devise (Object i w p n ) = (XObject i w (p / w) n p)
  15.  
  16. -- function to sort on efficiency
  17. sa = reverse(sortBy (compare `on` efficiency) (deviseAll tests))
  18.  
  19. -- The array of Objects
  20. tests = [ (Object 1 4.13 1.4 "Weapon and Ammunition")
  21.         ,(Object 2 2.13 2.74 "Water")
  22.         ,(Object 3 3.03 1.55 "Pith Helmet")
  23.         ,(Object 4 2.26 0.82 "Sun Cream")
  24.         ,(Object 5 3.69 2.38 "Tent")
  25.         ,(Object 6 3.45 2.93 "Flare Gun")
  26.         ,(Object 7 1.09 1.77 "Olive Oil")
  27.         ,(Object 8 2.89 0.53 "Firewood")
  28.         ,(Object 9 1.08 2.77 "Kendal Mint Cake")
  29.         ,(Object 10 3.23 4.29 "Snake Repellant Spray") 
  30.         ,(Object 11 2.29 2.85 "Bread")
  31.         ,(Object 12 0.55 0.34 "Pot Noodles")
  32.         ,(Object 13 2.82 (-0.45) "Software Engineering Textbook")
  33.         ,(Object 14 2.31 2.17 "Tinned food")
  34.         ,(Object 15 1.63 1.62 "Pork Pie")]
  35.        
  36. weights = [4.13, 2.13, 3.03, 2.26, 3.69, 3.45, 1.08, 2.89, 1.08, 3.23, 2.29, 0.55, 2.82, 2.31, 1.63]
  37. values = [1.4, 2.74, 1.55, 0.82, 2.38, 2.93, 1.77, 0.53, 2.77, 4.29, 2.85, 0.34, (-0.45), 2.17, 1.62]
  38. totalWeight = 20
  39.        
  40.     core x:xs p w | (w + (weight x)) > totalWeight core xs p w
  41.         | core [] p w = p
  42.         | otherwise (max a b)
Advertisement
Add Comment
Please, Sign In to add comment