Skip to content

Instantly share code, notes, and snippets.

@kana
Created July 26, 2012 09:53
Show Gist options
  • Save kana/3181279 to your computer and use it in GitHub Desktop.
Save kana/3181279 to your computer and use it in GitHub Desktop.
Haskellリハビリ中
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