Skip to content

Instantly share code, notes, and snippets.

@dradtke
Created March 27, 2012 20:05
Show Gist options
  • Select an option

  • Save dradtke/2219778 to your computer and use it in GitHub Desktop.

Select an option

Save dradtke/2219778 to your computer and use it in GitHub Desktop.
Haskell Solution for Reverse Words (Google Code Jam)
data Unsolved = Unsolved { unsolvedNumber :: Int, input :: String }
data Solved = Solved { solvedNumber :: Int, answer :: String }
instance Show Solved where
show (Solved n ans) = "Case #" ++ (show n) ++ ": " ++ ans
main :: IO ()
main = do
input <- fmap lines getContents
let input' = tail input
let cases = zipWith Unsolved [1..] input'
mapM_ putStrLn $ map (show.solve) cases
solve :: Unsolved -> Solved
solve (Unsolved n input) = Solved n ans
where ans = (unwords.reverse.words) input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment