Skip to content

Instantly share code, notes, and snippets.

@ulysses4ever
Last active May 5, 2020 16:31
Show Gist options
  • Save ulysses4ever/9b5b84b20dafe50fe609d26309e2a0dd to your computer and use it in GitHub Desktop.
Save ulysses4ever/9b5b84b20dafe50fe609d26309e2a0dd to your computer and use it in GitHub Desktop.
{-# 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 >>=
print
main = randTest 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment