Skip to content

Instantly share code, notes, and snippets.

@betaveros betaveros/gist:11311438
Last active Aug 29, 2015

Embed
What would you like to do?
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...
-- @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
You can’t perform that action at this time.