Skip to content

Instantly share code, notes, and snippets.

@RationalAsh
Created April 11, 2019 09:30
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 RationalAsh/b92dfab3970e5d9ba2b4855afedf0d5c to your computer and use it in GitHub Desktop.
Save RationalAsh/b92dfab3970e5d9ba2b4855afedf0d5c to your computer and use it in GitHub Desktop.
Solution to the Google Code Jam Qualification Round Problem #1
import Control.Monad
getA :: [Char] -> [Char]
getA n = map (\x -> if x == '4' then '2' else '0') n
getB :: [Char] -> [Char]
getB n = map (\x -> if x == '4' then '2' else x) n
solveCase :: [Char] -> (String, String)
solveCase n = (getA n, getB n)
caseSolutionString :: (Int, [Char]) -> String
caseSolutionString (i, n) = "Case #" ++ show i ++ ": " ++ fst sol ++ " " ++ snd sol
where sol = solveCase n
readCase :: Int -> IO (Int, String)
readCase i = do
nstr <- getLine
return (i, takeWhile (\c -> (c /= '\r') && (c /= '\n')) nstr)
main = do
t <- getLine
let tn = (read t) :: Int
cases <- forM [1..tn] readCase
mapM putStrLn (map caseSolutionString cases)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment