Last active
September 4, 2015 20:31
-
-
Save quephird/e54612c1d6ff4538a48b to your computer and use it in GitHub Desktop.
Solution to exercise 2 in section 8.7 in PureScript by Example
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
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment