-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp-contraryPairsResource.hs
39 lines (35 loc) · 1.55 KB
/
exp-contraryPairsResource.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
37
38
39
import Lotto
import Math.Combinat.Partitions
import qualified Data.Set as S
import Data.List (tails)
import Control.Monad
uniquePairs :: [t] -> S.Set (t, t)
uniquePairs xs = S.fromDistinctAscList [(x,y) | (x:xt) <- tails xs, y <- xt]
resourceMatrix :: Partition -> Partition -> [([Int], [Int])]
resourceMatrix (Partition xs) (Partition ys) =
let (xs', ys') = (resourceVec' xs ys, resourceVec' ys xs) in
if xs /= xs' || ys /= ys'
then (xs', ys') : resourceMatrix (Partition xs') (Partition ys')
else []
resourceMatrixResult :: (Num a, Eq a) => [([a], [a])] -> a
resourceMatrixResult [] = 0
resourceMatrixResult ((xs, ys) : restM) =
let s = signum (sum xs - sum ys) in
case s of 0 -> resourceMatrixResult restM
_ -> s
main :: IO ()
main = do
let (n, m) = (15, 5)
xs = allLottoPartitions n m
_ <- forM (S.toList (uniquePairs xs)) (\(x, y) -> do
let (l, t, w) = tommyLotto x y
isContrary = signum (force x y) /= signum (w - l)
when isContrary $ do
let rm = resourceMatrix x y
isContrary' = signum (w - l) /= resourceMatrixResult rm
putStrLn (if isContrary' then "!" else [])
putStrLn $ show (fromPartition x) ++ " vs " ++ show (fromPartition y) ++ ":"
putStrLn $ "\tWins: " ++ show w ++ ", Ties: " ++ show t ++ ", Losses: " ++ show l
_ <- forM rm (\(x', y') -> putStrLn $ "\t" ++ show x' ++ " = " ++ show (sum x') ++ " vs " ++ show y' ++ " = " ++ show (sum y'))
putStrLn "")
putStrLn ""