Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Stones Riddle (Beginners Haskell), see
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