Last active
August 29, 2015 14:17
-
-
Save shintakezou/440606ce22f81fd3c78b to your computer and use it in GitHub Desktop.
answer a puzzle (A problem for Susi) on an italian magazine
This file contains 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
{- | |
This code answers to "Un quesito con la Susi n. 923" | |
(a puzzle on an italian magazine). | |
Brute force, no optimization (and no Haskell guru here). | |
-} | |
import Data.List | |
checkSol :: [Int] -> Bool | |
checkSol a = | |
5*susi == gianni && (sum a) == (susi + gianni + tavolo) | |
where | |
susi = sum $ take 3 a | |
gianni = sum $ take 4 (drop 3 a) | |
tavolo = sum $ drop 7 a | |
sols :: [[Int]] | |
sols = filter checkSol (permutations [1..10]) | |
main = do | |
print $ (sum . drop 7 . head) sols | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment