Skip to content

Commit

Permalink
Shrunk main down to a single method call in CodeJam. Nice.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien Radtke committed Mar 19, 2012
1 parent 14ef825 commit 85b87cd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CodeJam.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ instance Show Case where
show (Unsolved number input) = "Case #" ++ (show number) ++ ": N/A"
show (Solved number answer) = "Case #" ++ (show number) ++ ": " ++ answer

codeJam :: (Input -> String) -> IO ()
codeJam solve = do
input <- fmap lines getContents
mapM_ putStrLn $ map (show.(solveCase solve)) $ getCases input

getCases :: Input -> [Case]
getCases input = zipWith Unsolved [1..] $ splitIntoCases input' linesPerCase
where n = read $ head input :: Int
Expand Down
7 changes: 1 addition & 6 deletions minimum-scalar/minimum-scalar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import CodeJam
import Data.List

main :: IO ()
main = do
input <- fmap lines getContents
mapM_ putStrLn $ map (show.(solveCase solve)) $ getCases input

linesPerCase :: Int
linesPerCase = 3
main = codeJam solve

solve :: Input -> String
solve input = show result
Expand Down
7 changes: 1 addition & 6 deletions reverse-words/reverse-words.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
import CodeJam

main :: IO ()
main = do
input <- fmap lines getContents
mapM_ putStrLn $ map (show.(solveCase solve)) $ getCases input

linesPerCase :: Int
linesPerCase = 1
main = codeJam solve

solve :: Input -> String
solve input = unwords.reverse.words $ head input
7 changes: 1 addition & 6 deletions store-credit/store-credit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import CodeJam
data Item = Item { index :: Int, price :: Int } deriving (Show)

main :: IO ()
main = do
input <- fmap lines getContents
mapM_ putStrLn $ map (show.(solveCase solve)) $ getCases input
main = codeJam solve

linesPerCase :: Int
linesPerCase = 3

solve :: Input -> String
solve input = formatAnswer res1 res2
where (l1:l2:l3:_) = input
Expand Down

0 comments on commit 85b87cd

Please sign in to comment.