Last active
December 29, 2015 10:19
-
-
Save yaf/7655903 to your computer and use it in GitHub Desktop.
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
import Test.HUnit | |
main = do runTestTT $ TestList [ | |
juge [Rouge, Vert, Orange, Bleu] [Rouge, Vert, Orange, Bleu] ~?= End True | |
,juge [Rouge, Vert, Orange, Bleu] [Jaune, Vert, Jaune, Jaune] ~?= Retry (BienPlacé 1, MalPlacé 0) | |
,juge [Rouge, Vert, Orange, Bleu] [Jaune, Vert, Orange, Jaune] ~?= Retry (BienPlacé 2, MalPlacé 0) | |
,juge [Rouge, Vert, Orange, Bleu] [Vert, Jaune, Jaune, Jaune] ~?= Retry (BienPlacé 0, MalPlacé 1) | |
,juge [Rouge, Orange, Rouge, Rouge] [Orange, Orange, Orange, Orange] ~?= Retry (BienPlacé 1, MalPlacé 0) | |
] | |
data Couleur = Rouge | Vert | Orange | Bleu | Jaune | |
deriving (Eq) | |
data Resultat = End Bool | Retry (BienPlacé, MalPlacé) | |
deriving (Show, Eq) | |
data BienPlacé = BienPlacé Int | |
deriving (Show, Eq) | |
data MalPlacé = MalPlacé Int | |
deriving (Show, Eq) | |
type Secret = [Couleur] | |
type Proposition = [Couleur] | |
juge :: Secret -> Proposition -> Resultat | |
juge s p | |
| s == p = End True | |
| otherwise = Retry (BienPlacé bp, MalPlacé (min mp mp')) | |
where | |
compterLesTrue = length . filter (==True) | |
bp = compterLesTrue $ zipWith (==) s p | |
compterLesMalPlacé x y = (compterLesTrue $ map (`elem` x) y) - bp | |
mp = compterLesMalPlacé s p | |
mp' = compterLesMalPlacé p s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Je crois qu'il manque un autre fichier, celui où tu as juste fait
run qqchoz
, non ?