Skip to content

Instantly share code, notes, and snippets.

@CarstenKoenig
Created May 2, 2015 20:41
Show Gist options
  • Save CarstenKoenig/0fc1ff33b7f92cbb1b13 to your computer and use it in GitHub Desktop.
Save CarstenKoenig/0fc1ff33b7f92cbb1b13 to your computer and use it in GitHub Desktop.
combinations in a knapsack
combinations :: Int -> [Int] -> [[Int]]
combinations _ [] = [[]]
combinations w (x:xs)
| w >= x = [ x:ys | ys <- combinations (w-x) xs] ++ combinations w xs
| otherwise = combinations w xs
@Larsen00
Copy link

Won't this give you duplicates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment