Last active
May 5, 2020 16:31
-
-
Save ulysses4ever/9b5b84b20dafe50fe609d26309e2a0dd to your computer and use it in GitHub Desktop.
This file contains 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 characters
{-# LANGUAGE FlexibleContexts #-} | |
import Control.Monad | |
import Control.Monad.ST | |
import Control.Exception | |
import System.Random | |
import Data.Functor | |
import qualified Data.Vector.Generic.Mutable as V | |
import qualified Data.Vector.Unboxed as U | |
m = 120 | |
task27 :: [Int] -> (Int, Int) | |
task27 l = runST $ do | |
r <- V.replicate m 0 :: ST s (U.MVector s Int) | |
let go [] = return (1,2) | |
go (a:as) = do | |
let p = a `mod` m | |
cur_lead <- r `V.read` p | |
when (a > cur_lead) (V.write r p a) | |
go as | |
go l | |
randTest :: | |
Int -> -- Length of random testing sequence | |
IO () | |
randTest n = | |
newStdGen <&> | |
randoms <&> | |
take n <&> | |
task27 >>= | |
main = randTest 1000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment