Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Sums where
- import Data.Array ((:), foldM, nub, sort)
- import Data.Maybe (Maybe(..))
- import Prelude (($), (+), (++), map)
- -- Given an array of integers, compute the list of all
- -- possible totals, using each integer at most once.
- sums :: Array Int -> Maybe (Array Int)
- sums = foldM (\a e -> Just $ sort $ nub $ (e :) $ map (+e) a ++ a) [0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement