ProjectEuler.net problem 54. Покер.

module where DataList DataOrd DebugTrace Val C2 C3 C4 C5 C6 C7 C8 C9 CT J Q K A (, , , , ) Suit H C S D (, , , , ) Card Card val Valsuit Suitderiving EqOrdShowvals map suits map allEqual = allEqual ccs= (ccs [] True (:) True (::) succ == && (:) cs maximum vals ) [] (, ) cs maximumBy comparing ) isRoyalFlush = cs [, , , , ] isFlush isStraightFlush = cs isFlush nthSameVal n map \-> xcs x) filter \-> x n allEqual vals )$ cs cs maxByFst nthSameVal 4 cs ((, ) (, $ $ rest )$ $ cs isFlush = (csisStraight = (csisThreeOfAKind = $ cs isTwoPair = \xrest-> xmaxByFst nthSameVal 2) maxByFst nthSameVal 2 cs maxByFst nthSameVal 2 Rank N1 Val| Val Val| Val [] N3 [] St Val| [] FH Val FOC | Val RF (, , ) cs isRoyalFlush = | cs SF maximum rvals | foc FOC extractHeadVal foc nnf && fh FH extractHeadVal fh(snd ) isFlush = $ cs isStraight = $ cs nnf = (fst ) rvals snd ) nnf && n22' N22 extractHeadVal n22(fst ) rvals snd ) nnf = (fst ) rvals snd ) otherwise N1 rvals where f = $ $ cs' cs reverse sort vals nnf = $ $ x x not null snd foc isFourOfAKind fh isFullHouse n3 isThreeOfAKind n22 isTwoPair n22' snd n2 isOnePair readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readVal = readSuit = readSuit = readSuit = readSuit = readCard s1s2[]= (s1(s2readLine = rank , g2where = s = $ readCard take ws = $ readCard drop ws :: () = l readFile let = l r map ls print length filter $ (()r ()
|
</> |