Created
July 26, 2012 09:53
-
-
Save kana/3181279 to your computer and use it in GitHub Desktop.
Haskellリハビリ中
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 Data.List | |
data Card = | |
Nouson | |
| Toshi | |
| Daitoshi | |
| MinaraiJijo | |
| YakihataNougyo | |
deriving (Eq, Show) | |
type Hand = [Card] | |
type Deck = [Card] | |
levy :: Hand -> Card -> Int | |
levy hand Nouson = if YakihataNougyo `elem` hand then 2 else 1 | |
levy _ Toshi = 2 | |
levy _ Daitoshi = 3 | |
levy _ MinaraiJijo = 0 | |
levy _ YakihataNougyo = 0 | |
simulateTurn :: Hand -> Int | |
simulateTurn hand = sum $ map (levy hand) hand | |
simulateGame :: Deck -> [Int] | |
simulateGame deck = | |
[ | |
simulateTurn $ take 5 deck, | |
simulateTurn $ take 5 $ drop 5 deck | |
] | |
main :: IO () | |
main = | |
putStr $ unlines $ map show $ map (\coinss -> (head coinss, length coinss)) $ group $ sort $ map simulateGame possibleDecks | |
where | |
initialDeck = (replicate 7 Nouson) ++ (replicate 3 MinaraiJijo) | |
theDeck = initialDeck -- TODO | |
possibleDecks = permutations theDeck | |
possibleGameCount = length possibleDecks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment