Anonymous user
Poker hand analyser: Difference between revisions
m
→Basic Version
m (→Basic Version) |
m (→Basic Version) |
||
Line 1,982:
parseCard :: String -> Maybe Card
parseCard [] = Nothing
parseCard xs = (\a b -> Card a b) <$>
where
where r = init xs
where s = head $ reverse xs
nameHand :: String -> String
nameHand s
| invalidHand = ": invalid"
| straight && flush = ": straight-flush"
| ofKind 4 = ": four-of-a-kind"
|
| flush = ": flush"
| straight = ": straight"
Line 2,019:
where cards = catMaybes $ map parseCard $ words s
sortedRank = sort $ map rank cards
where
rankCount c@(x:xs) = (x, length c)
sortedGroups = sortBy (\(_, n) (_, n') -> compare n' n)
uniqRanks = length ranks
ofKind n = any (\(_, y) -> n == y) ranks
Line 2,028 ⟶ 2,029:
flush = and $ map (\c -> s == suit c) cards
where s = suit $ head cards
invalidHand = length
testHands :: [String]
|