summaryrefslogtreecommitdiff
path: root/2023/haskell/day01/part1.hs
diff options
context:
space:
mode:
authorcos <cos>2023-12-01 23:58:06 +0100
committercos <cos>2023-12-03 14:55:14 +0100
commit9cd5b11547e2805359271703944e316cc071eb67 (patch)
tree27a406e72329a5815f2583c71f3be2bf934c6585 /2023/haskell/day01/part1.hs
parentaefd26f3d7bf22bbc3f29c1f2cb18e91c28cf363 (diff)
downloadadventofcode-9cd5b11547e2805359271703944e316cc071eb67.zip
Add day01, 2023 (haskell)HEADmaster
Diffstat (limited to '2023/haskell/day01/part1.hs')
-rw-r--r--2023/haskell/day01/part1.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/2023/haskell/day01/part1.hs b/2023/haskell/day01/part1.hs
new file mode 100644
index 0000000..65ea098
--- /dev/null
+++ b/2023/haskell/day01/part1.hs
@@ -0,0 +1,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."