Skip to content

Instantly share code, notes, and snippets.

@betaveros
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betaveros/11311438 to your computer and use it in GitHub Desktop.
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...
-- @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