Commit ee40de93 authored by Ian Lynagh's avatar Ian Lynagh

Test for #149 (missed CSE opportunity)

parent 86a543fe
......@@ -14,3 +14,4 @@ test('simplrun002', normal, compile_and_run, [''])
test('simplrun003', normal, compile_and_run, [''])
test('simplrun004', normal, compile_and_run, [''])
test('simplrun005', normal, compile_and_run, [''])
test('simplrun006', normal, compile_and_run, [''])
module Main (main) where
import System.CPUTime
main = do start <- getCPUTime
putStrLn "Start"
print $ playerMostOccur1 [1..m]
middle <- getCPUTime
putStrLn "Middle"
print $ playerMostOccur2 [1..m]
end <- getCPUTime
putStrLn "End"
let d1 = middle - start
d2 = end - middle
if d1 > 2 * d2
then do print d1
print d2
else putStrLn "OK!"
m :: Int
m = 22
playerMostOccur1 :: [Int] -> Int
playerMostOccur1 [a] = a
playerMostOccur1 (x:xs)
| numOccur x (x:xs) > numOccur (playerMostOccur1 xs) xs = x
| otherwise = playerMostOccur1 xs
playerMostOccur2 :: [Int] -> Int
playerMostOccur2 [a] = a
playerMostOccur2 (x:xs)
| numOccur x (x:xs) > numOccur pmo xs = x
| otherwise = pmo
where pmo = playerMostOccur2 xs
numOccur :: Int -> [Int] -> Int
numOccur i is = length $ filter (i ==) is
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment