25 lines
834 B
Haskell
25 lines
834 B
Haskell
import System.IO
|
|
import Control.Monad
|
|
|
|
main = do
|
|
let list = []
|
|
inputHandle <- openFile "../data/2015/1/input.txt" ReadMode
|
|
input <- hGetContents inputHandle
|
|
putStr "Part 1: "
|
|
putStrLn $ finalFloor input 0
|
|
|
|
putStr "Part 2: "
|
|
putStrLn $ basementSteps input 0 0
|
|
hClose inputHandle
|
|
|
|
finalFloor :: String -> Int -> String
|
|
|
|
finalFloor ('(' : rest) floor = finalFloor rest (floor + 1)
|
|
finalFloor (')' : rest) floor = finalFloor rest (floor - 1)
|
|
finalFloor _ floor = show floor
|
|
|
|
basementSteps :: String -> Int -> Int -> String
|
|
basementSteps _ (-1) steps = show steps
|
|
basementSteps ('(' : rest) floor steps = basementSteps rest (floor + 1) (steps + 1)
|
|
basementSteps (')' : rest) floor steps = basementSteps rest (floor - 1) (steps + 1)
|
|
basementSteps _ _ steps = show steps |