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