Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Random
- maxC = 23
- data CardState = CardState { num0 :: Int
- , num1 :: Int
- , cards :: [Int]
- } deriving (Show)
- makeList :: [Int] -> CardState -> CardState
- makeList (x:xs) n | n0 >= maxC && n1 >= maxC = n
- | n0 >= maxC && x == 0 = makeList xs n
- | n1 >= maxC && x == 1 = makeList xs n
- | x == 0 = makeList xs $ CardState (n0 + 1) n1 (cs ++ [x])
- | x == 1 = makeList xs $ CardState n0 (n1 + 1) (cs ++ [x])
- where n0 = num0 n
- n1 = num1 n
- cs = cards n
- checkWin (x:xs) | length xs <= 2 = x == 0
- | x == 1 && xs !! 1 == 1 = xs !! 2 == 0
- | otherwise = checkWin xs
- runTrial = do g <- newStdGen
- let xs = randomRs (0,1) g :: [Int]
- let xs' = makeList xs (CardState 0 0 [])
- return $ checkWin (cards xs')
- main = do xs <- mapM (\x -> runTrial) [1..10000]
- print $ fromIntegral (length (filter (==True) xs)) / fromIntegral (length xs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement