Skip to content

Instantly share code, notes, and snippets.

@marcosccm
Created May 31, 2012 19:06
Show Gist options
  • Save marcosccm/2845491 to your computer and use it in GitHub Desktop.
Save marcosccm/2845491 to your computer and use it in GitHub Desktop.
wcc 2012.22
import Data.List
import Data.Function
wcc :: (Ord a, Num a) => a -> [a] -> [[a]]
wcc x = maximumBy (greaterSum) . groupBy (sameSum) . filter (sumSmallerThenTarget) . subsequences . filter (< x) . sort
where sumSmallerThenTarget xs = (sum xs) < x
sameSum a b = sum a == sum b
greaterSum = compare `on` (sum . concat)
@bltavares
Copy link

You can replace 'total' with 'sum'

@marcosccm
Copy link
Author

Thanks!

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