import Card import Pile import Utils import qualified Data.Map.Strict as M import Data.Monoid ((<>)) type Guess = M.Map Card [Hand] type Distribution = ([Card], [Card], [Card]) distributions :: Guess -> [Distribution] distributions guess = --filter equilibrated (helper (M.toList guess) (0, 0, 0)) where helper [] _ = [] helper ((c, hs):[]) ns = map fst (distr c hs ns) helper ((c, hs):gs) ns = let dsWithNs = distr c hs ns go (d, ns') = map (d <>) (helper gs ns') in concatMap go dsWithNs distr card hands (n1, n2, n3) = let f card Hand1 = (([card], [], []), (n1+1, n2, n3)) f card Hand2 = (([], [card], []), (n1, n2+1, n3)) f card Hand3 = (([], [], [card]), (n1, n2, n3+1)) isOk Hand1 = n1 < cardsPerHand isOk Hand2 = n2 < cardsPerHand isOk Hand3 = n3 < cardsPerHand in filterMap isOk (f card) hands equilibrated (cs1, cs2, cs3) = let ls = [length cs1, length cs2, length cs3] in (maximum ls - minimum ls) <= 1 cardsPerHand = (length guess `div` 3) testguess :: Guess testguess = foldr (Hand3 `has`) m (take 10 allCards) where l = map (\c -> (c, [Hand1, Hand2, Hand3])) (take 30 allCards) m = M.fromList l main :: IO () main = print $ length $ distributions testguess