Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Created June 8, 2017 03:01
Show Gist options
  • Save NotTheEconomist/0ddde537ad9b1bc20f90d9ed7fc257d2 to your computer and use it in GitHub Desktop.
Save NotTheEconomist/0ddde537ad9b1bc20f90d9ed7fc257d2 to your computer and use it in GitHub Desktop.
import Control.Monad
problem1 :: IO ()
problem1 = do
input <- replicateM 3 getLine
putStrLn $ show . sum . map (read :: String -> Int) $ input
problem2 :: IO ()
problem2 = do
input <- replicateM 2 getLine
let (a:b:[]) = map (read :: String -> Float) input
putStrLn $ show $ a * b / 2
problem3 :: IO ()
problem3 = do
input <- replicateM 2 getLine
let (students:apples:[]) = map (read :: String -> Int) input
let (d, m) = apples `divMod` students
putStrLn $ show d
putStrLn $ show m
problem4 :: IO ()
problem4 = do
input <- getLine
let (h, m) = read input `divMod` 60
putStrLn $ show h ++ " " ++ show m
problem5 :: IO ()
problem5 = do
input <- getLine
putStrLn $ "Hello, " ++ input ++ "!"
problem6 :: IO ()
problem6 = do
input <- getLine
let n = read input :: Integer
putStrLn $ "The next number for the number " ++ input ++ " is " ++ show (succ n) ++ "."
putStrLn $ "The previous number for the number " ++ input ++ " is " ++ show (pred n) ++ "."
problem7 :: IO ()
problem7 = do
desks <- replicateM 3 (do
a <- getLine
let a' :: Int
a' = succ . read $ a
return $ a' `div` 2)
putStrLn $ show . sum $ desks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment