Skip to content

Instantly share code, notes, and snippets.

@jhickner
Last active December 12, 2015 04:59
Show Gist options
  • Save jhickner/4718757 to your computer and use it in GitHub Desktop.
Save jhickner/4718757 to your computer and use it in GitHub Desktop.
import Data.List (inits, tails, sortBy)
import Data.Ord (comparing)
type Result = ([Int], Int)
cSum :: [Int] -> [Result]
cSum = reverse . sortBy (comparing snd) . map result . cSubs
where
result xs = (xs, sum xs)
cSubs = concatMap (tail . inits) . tails
--λ> cSum [1, 2, 3]
-- [([1,2,3],6),([2,3],5),([3],3),([1,2],3),([2],2),([1],1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment