Skip to content

@zenon /gist:1327860
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Stones Riddle (Beginners Haskell), see http://beust.com/weblog/2011/10/30/a-new-coding-challenge/
import Data.List
allStones = [[a,b,c,d]| a <- [1..39], b <- [a..39], c <- [b..39], d <- [c..39], a+b+c+d==40]
combineWeights [x] = [-x, 0, x]
combineWeights (x:xs) = concat $ map (\w -> [w-x, w, w+x]) (combineWeights xs)
result = filter (\x -> ((sort $ filter (>0) $ nub $ map abs (combineWeights x)) == [1..40])) allStones
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.