From 786dfe4bb8fccf445532d8209da48be2d5a41696 Mon Sep 17 00:00:00 2001 From: Sasha Date: Sun, 25 Feb 2018 23:17:51 +0100 Subject: [PATCH] Expose the size of card packs --- Card.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Card.hs b/Card.hs index a71b409..b706427 100644 --- a/Card.hs +++ b/Card.hs @@ -71,6 +71,9 @@ port f bits = f bits . fromEnum contains :: Pack -> Card -> Bool contains = port testBit +size :: Pack -> Int +size = popCount + add :: Pack -> Card -> Pack add = port setBit @@ -106,7 +109,7 @@ shuffle l = pair :: Card -> Pack -> Maybe (Pack, Pack) pair card pack = let sameMonthCards = sameMonth card `intersection` pack in - case popCount sameMonthCards of + case size sameMonthCards of 0 -> Just (add pack card, empty) 1 -> Just (difference pack sameMonthCards, add sameMonthCards card) _ -> Nothing