2 module Htirage.Draw where
6 -- * Sélection de choix
8 -- | @draw1 bs cs@ retourne un choix de la liste de choix 'cs'
9 -- déterminé par le premier nombre binaire formé par l’entropie 'bs'
10 -- qui a le potentiel d’atteindre tous les choix,
11 -- et qui en atteint effectivement un.
12 draw1 :: [Bool] -> [a] -> a
14 | given < enough = error (show (enough - given) ++ " missing bits")
15 | i > iMax = draw1 (tail bits ++ bs') cs
17 where (bits, bs') = splitAt enough bs
24 -- | @drawComb k cs ns@ retourne les 'k' choix parmi 'cs', déterminés par les bits 'bs'.
25 drawComb :: Int -> [a] -> [Bool] -> [a]
26 drawComb k cs bs = draw1 bs (k`combs'Dyn`cs)
28 | given < enough = error (show (enough - given) ++ " missing bits")
29 | i > iMax = drawComb k (tail bits ++ bs') cs
30 | otherwise = combOfRank k n i `applyPerm` cs
31 where (bits, bs') = splitAt enough bs
39 pr l = putStrLn (foldMap (\x -> show x ++ " ") l)
41 res = forM_ (zipWith (,) [0..] $ allCombsB 5 9) (\(i,l) -> putStr (show i ++ ": ") >> pr l)
42 allCombsB k n = combAt'Buckles k n <$> [0..k`combsIn`n - 1]