Skip to content

Instantly share code, notes, and snippets.

@codecontemplator
Last active November 4, 2016 21:56
Show Gist options
  • Save codecontemplator/6ba276b708ec3a8fc38e897ef6314680 to your computer and use it in GitHub Desktop.
Save codecontemplator/6ba276b708ec3a8fc38e897ef6314680 to your computer and use it in GitHub Desktop.
import Data.List
solve xs t = nub $ map sort $ solve' xs [] t
where
solve' _ solution 0 = [solution]
solve' [] _ _ = []
solve' (x:xs) solution t = solve' xs (x:solution) (t-x) ++ solve' xs solution t
test = solve [1,3,3,3,9] 10
--[[3,3,3,1],[9,1]]
test2 = solve [1,3,3,4,5,3,9] 10
--[[1,3,3,3],[1,4,5],[1,9],[3,3,4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment