Expose the size of card packs
This commit is contained in:
parent
c2a324b905
commit
786dfe4bb8
1 changed files with 4 additions and 1 deletions
5
Card.hs
5
Card.hs
|
@ -71,6 +71,9 @@ port f bits = f bits . fromEnum
|
||||||
contains :: Pack -> Card -> Bool
|
contains :: Pack -> Card -> Bool
|
||||||
contains = port testBit
|
contains = port testBit
|
||||||
|
|
||||||
|
size :: Pack -> Int
|
||||||
|
size = popCount
|
||||||
|
|
||||||
add :: Pack -> Card -> Pack
|
add :: Pack -> Card -> Pack
|
||||||
add = port setBit
|
add = port setBit
|
||||||
|
|
||||||
|
@ -106,7 +109,7 @@ shuffle l =
|
||||||
pair :: Card -> Pack -> Maybe (Pack, Pack)
|
pair :: Card -> Pack -> Maybe (Pack, Pack)
|
||||||
pair card pack =
|
pair card pack =
|
||||||
let sameMonthCards = sameMonth card `intersection` pack in
|
let sameMonthCards = sameMonth card `intersection` pack in
|
||||||
case popCount sameMonthCards of
|
case size sameMonthCards of
|
||||||
0 -> Just (add pack card, empty)
|
0 -> Just (add pack card, empty)
|
||||||
1 -> Just (difference pack sameMonthCards, add sameMonthCards card)
|
1 -> Just (difference pack sameMonthCards, add sameMonthCards card)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
Loading…
Reference in a new issue