aoc2021/Day1.hs

19 lines
433 B
Haskell
Raw Normal View History

2021-12-02 13:44:17 +00:00
module Day1 where
import System.IO (openFile, IOMode (ReadMode), hClose, hGetContents)
strToInts :: String -> [Int]
strToInts = map read . lines
depth :: [Int] -> Int
depth [] = 0
depth [x] = 0
depth (x:xs)
| head xs > x = 1 + depth xs
| otherwise = depth xs
main :: IO ()
main = do
input <- openFile "inputs/1.txt" ReadMode
contents <- hGetContents input
print $ depth $ strToInts contents
hClose input