lookup n = case n of 1 -> "A" 2 -> "B" 3 -> "C" _ -> "X" -- Knapsack! But, first, we do subsets... subsets [] = [[]] subsets (x:xs) = subsWithX ++ subsWithoutX where subsWithoutX = subsets xs subsWithX = map (x:) subsWithoutX -- Now, knapsack. List of three-tuples, (name, value, weight) value sub = sum (map (\(_,val,_)->val) sub) weight sub = sum (map (\(_,_,weight)->weight) sub) knapsack items limit = ... where -- options is a list of the sets of items that will fit options = filter (\set->weight set<=limit) (subsets items)