[ create a new paste ] login | about

Link: http://codepad.org/aiJhoNmq    [ raw code | output | fork | 1 comment ]

mohit_at_codepad - Haskell, pasted on Apr 2:
-- Written by Mohit Jain
-- Input is a poker hand
-- Output the analysis as described @ snippet below
-- http://codepad.org/HS8z6MZd
module Main where

-- Import List to enable sort
import List

poker= toPokerStr . sortBy (flip compare) . map length . group
 . sort . filter (\x -> notElem x "HSDC") . filter ( (/=) '0' )
toPokerStr x = ["--", "1P", "3K", "4K", "2P", "FH"] !! (x !! 0 + 3 * x !! 1 - 4)

main = putStr $ unlines $ map poker inputList
inputList = [
    "H6D6D4C6S6", "S7D7C7H8H7", "SADAHACAS8", "C4H4D6D4S4", "DAC9HASACA",
    "H2C2S2D2H9", "C3H8D8C8S8", "S10C9D10H9H10", "CAHAS10H10D10", "D5H5S5H3C3",
    "D3C3C10D10S3", "D7H7SADAHA", "D7CAC7SAHA", "CKHKC7D7DK", "D3H3DKS3C7",
    "S8H2C8H7H8", "S3SAD2H3C3", "CADAC9C7SA", "SAD7S7C3C7", "H10S4D3S3C3",
    "HJDKC7SKHK", "D3H3S5H10C5", "S3H8C8D7D3", "H5S3C5H4D4", "S8D10HJS10CJ",
    "C9D8H4D4D9", "C10CAH5S10C5", "H9S10H10DASA", "H10CJH6C7D7", "C3C10DKS4CK",
    "SJH6S7C8D6", "HKS5C10S8H5", "HKS5H10H3SK", "HAHJC2DACK", "D2S2C9H4C8",
    "DQC4SQD5CK", "D4H3HJSKS10", "S3C5D9S6DA", "CJD5H9H6D2", "H6C10D9S3H7",
    "H9DJHQH7C8", "C7D3CJD2S9"]

-- eof


Output:
4K
4K
4K
4K
4K
4K
4K
FH
FH
FH
FH
FH
FH
FH
3K
3K
3K
3K
3K
3K
3K
2P
2P
2P
2P
2P
2P
2P
1P
1P
1P
1P
1P
1P
1P
1P
--
--
--
--
--
--


Create a new paste based on this one


Comments:
posted by mohit_at_codepad on Apr 3
filter (\x -> notElem x "HSDC") . filter ( (/=) '0' )
is same as

filter (\x -> notElem x "HSDC0")
reply