Add tags

Add tags to the following comment

初投稿です。Cleanです。この辺のライブラリを使ってます。

http://sourceforge.net/projects/cleanoptenv

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Main

import System, Int, Char, String, List, Misc, MergeSort, ValueCast

Start
  | flush cards
    | straight cards
      | 14 == num (head cards)
        = "Royal flush"
      = "Straight flush"
    = "Flush"
  | straight cards
    = "Straight"
  | 4 == head groups
    = "Four of a kind"
  | 3 == head groups
    | 2 == groups !! 1
      = "Full house"
    = "Three of a kind"
  | 2 == head groups
    | 2 == groups !! 1
      = "Two pair"
    = "One pair"
  = "No pair"
  where
  cards = sortBy (>) $ parseCards getCommandLine.[1]
  groups = sortBy (>) $ map length $ groupCards [[]] 0 cards

:: Card = Card !Char !Int //suit num(2..14)
instance < Card where
  (<) (Card s0 n0) (Card s1 n1) = n0 < n1

suit (Card s n) = s
num (Card s n) = n

parseCards t = p 0
  where
  l = size t
  p i | i >= l = []
      = [Card s n: p (i+2)]
    where
    s = t.[i]
    n = case t.[i+1] of
          'A' = 14
          'K' = 13
          'Q' = 12
          'J' = 11
          'T' = 10
          c   = toInt (c - '0')

groupCards ls _ [] = ls
groupCards [l:ll] m [c=:Card s n: rest]
  | m == n = groupCards [[c:l]:ll] n rest
           = groupCards [[c],l:ll] n rest

flush cards = and $ zipWith (==) suits (tail suits)
  where
  suits = map suit cards

straight cards = (and $ zipWith (\a b = a == b + 1) nums (tail nums))
              || caseAce nums
  where
  nums = map num cards
  caseAce [14,5,4,3,2] = True
  caseAce _ = False

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...