summaryrefslogtreecommitdiff
path: root/2023/haskell/day01/part1.hs
blob: 65ea098f25c80bf9695d7bb2f58b9bbe6d1dbe34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import Data.Char
import System.Environment
import System.IO

main :: IO ()
main = do
  args <- getArgs
  case args of
    [filename] -> do
      fh <- openFile filename ReadMode
      lines <- lines <$> readFile filename
      let digits = map (\line -> [c | c <- line, isDigit c ]) lines
      let numbers = map (\line -> head line : [last line]) digits
      let ints = map (\num -> read num :: Int ) numbers
      let part1 = sum ints
      print part1
    _ -> putStrLn "Missing input filename."