Last active
August 29, 2015 14:00
-
-
Save betaveros/11311438 to your computer and use it in GitHub Desktop.
Google Code Jam Round 1A 2014 problem C: Proper Shuffle. Testing on my machine correctly identified 88.6% of 1000 good shuffles and 98.1% of 1000 bad shuffles. I don't know why...
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 characters
-- @betaveros | |
-- Google Code Jam Round 1A 2014: Proper Shuffle (polished version) | |
import Control.Applicative | |
import Control.Monad | |
import Text.Printf | |
inputInt :: IO Int | |
inputInt = read <$> getLine | |
inputInts :: IO [Int] | |
inputInts = map read . words <$> getLine | |
countAgainstIndex :: (Int -> Int -> Bool) -> [Int] -> Int | |
countAgainstIndex vs = length . filter id . zipWith vs [0..] | |
guessBad :: [Int] -> Bool | |
guessBad ls = countAgainstIndex (>) ls < countAgainstIndex (<) ls - 20 | |
tc :: Int -> IO () | |
tc tci = do | |
_ <- inputInt | |
perm <- inputInts | |
printf "Case #%d: %s\n" tci $ if guessBad perm then "BAD" else "GOOD" | |
main :: IO () | |
main = do | |
tcn <- inputInt | |
forM_ [1..tcn] tc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment