Skip to content

Instantly share code, notes, and snippets.

@zenon
Created October 31, 2011 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zenon/1327860 to your computer and use it in GitHub Desktop.
Save zenon/1327860 to your computer and use it in GitHub Desktop.
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