Skip to content

Instantly share code, notes, and snippets.

@Abizern
Created April 18, 2014 09:47
Show Gist options
  • Save Abizern/11034826 to your computer and use it in GitHub Desktop.
Save Abizern/11034826 to your computer and use it in GitHub Desktop.
Solution to Google Code Jam 2014. Qualification-A Magic Trick https://code.google.com/codejam/contest/2974486/dashboard#s=p0
module Main where
import Control.Monad
import Data.List
-- https://code.google.com/codejam/contest/dashboard?c=2974486#s=p0
-- Input and output with standard redirection operators
-- Unless otherwise indicated, all modules used are either bundled with
-- the Haskell Platform (http://hackage.haskell.org/platform/) or available
-- as a separate download from Hackage (http://hackage.haskell.org/).
solve :: [Int] -> [Int] -> String
solve a b
| l == 1 = show $ head common
| l > 1 = "Bad magician!"
| otherwise = "Volunteer cheated!"
where common = a `intersect` b
l = length common
main :: IO ()
main = do
t <- getLine
forM_ [1..read t :: Int] $ \i -> do
choice1 <- fmap read getLine
initial <- replicateM 4 $ fmap (map read . words) getLine
choice2 <- fmap read getLine
final <- replicateM 4 $ fmap (map read . words) getLine
let r1 = initial !! (choice1 - 1)
r2 = final !! (choice2 - 1)
putStrLn $ concat ["Case #", show i, ": ", solve r1 r2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment