Created
May 2, 2015 20:41
-
-
Save CarstenKoenig/0fc1ff33b7f92cbb1b13 to your computer and use it in GitHub Desktop.
combinations in a knapsack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Won't this give you duplicates?