-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponse.hs
36 lines (29 loc) · 1.1 KB
/
Response.hs
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
module Response (response) where
import Data.List
import Card
response :: [Card] -> [Card] -> (Int, Int, Int, Int, Int)
response answer guess = (c, l, r, u, s)
where
c = getOccurances guess answer
r = getOccurancesR guess answer
s = getOccurancesS guess answer
l = length $ filter
(\x -> x < minimum (card2Rank guess)) (card2Rank answer)
u = length $ filter
(\x -> x > maximum (card2Rank guess)) (card2Rank answer)
getOccurances :: Eq a => [a] -> [a] -> Int
getOccurances guess answer
= length answer - length (removeOccurances guess answer)
getOccurancesR :: [Card] -> [Card] -> Int
getOccurancesR guess answer =
getOccurances (card2Rank guess) (card2Rank answer)
getOccurancesS :: [Card] -> [Card] -> Int
getOccurancesS guess answer =
getOccurances (card2Suit guess) (card2Suit answer)
removeOccurances :: Eq a => [a] -> [a] -> [a]
removeOccurances (x:xs) cards = removeOccurances xs (delete x cards)
removeOccurances [] cards = cards
card2Rank :: [Card] -> [Rank]
card2Rank cards = map rank cards
card2Suit :: [Card] -> [Suit]
card2Suit cards = map suit cards