Last active
September 8, 2015 10:56
Revisions
-
fgrsnau revised this gist
Sep 8, 2015 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ module Main where import Data.List import Data.List.Split import Data.Ratio import System.Random data Coin = Head | Tail deriving (Eq, Enum, Read, Show) @@ -21,4 +20,4 @@ main = do let outcomes = product . map (const (2 :: Integer)) <$> trials let average = let n = 1e7 in sum (take n outcomes) % (fromIntegral n) print (fromRational average) -
fgrsnau created this gist
Sep 8, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ {-# LANGUAGE NumDecimals #-} module Main where import Data.List import Data.List.Split import Data.Ratio import System.IO.Unsafe import System.Random data Coin = Head | Tail deriving (Eq, Enum, Read, Show) instance Random Coin where randomR (lo, hi ) g = let (x, g') = randomR (fromEnum lo, fromEnum hi) g in (toEnum x, g') random = randomR (Head, Tail) main :: IO () main = do coins <- randoms <$> newStdGen let trials = splitWhen (== Head) coins let outcomes = product . map (const (2 :: Integer)) <$> trials let average = let n = 1e7 in sum (take n outcomes) % (fromIntegral n) print (fromRational average)