DEV Community

Discussion on: Daily Challenge #142 - Parts of a Whole

Collapse
 
craigmc08 profile image
Craig McIlwrath

Haskell! Uses the TupleSections extension to the compiler to make the pairs function nicer.

{-# LANGUAGE TupleSections #-} 

import Data.Char (digitToInt) 

digits :: Int -> [Int] 
digits = map digitToInt . show

pairs :: [a] -> [(a, a)] 
pairs (x:[]) = [] 
pairs (x:xs) = map (x,) xs ++ pairs xs

allSums :: Int -> [Int] 
allSums = map (uncurry (+)) . pairs . digits