summary refs log tree commit diff
diff options
context:
space:
mode:
authorCrazazy2024-12-01 14:15:18 +0100
committerCrazazy2024-12-01 14:15:18 +0100
commit5ba0d95a80c06a39e65abc52200ee2fd7ee90bda (patch)
tree5793633e2fa7bcb859ffdcf406bc09ea8bfb6e5f
parent911796e471b30f7b1d8358e9d9d179852cfebfc5 (diff)
made some AoC infrastructure
-rw-r--r--aoc-2024.ipkg8
-rw-r--r--src/Day1.idr13
-rw-r--r--src/Main.idr22
3 files changed, 33 insertions, 10 deletions
diff --git a/aoc-2024.ipkg b/aoc-2024.ipkg
index c38e564..363c432 100644
--- a/aoc-2024.ipkg
+++ b/aoc-2024.ipkg
@@ -1,7 +1,7 @@
 package aoc
-modules =
-    Day1
+modules = Main
+        , Day1
 depends = contrib
 sourcedir = "src"
-main = Day1
-executable = day1
+main = Main
+executable = aoc
diff --git a/src/Day1.idr b/src/Day1.idr
index 96cf777..e29b0a7 100644
--- a/src/Day1.idr
+++ b/src/Day1.idr
@@ -27,9 +27,10 @@ occur x fs = foldr (\y => \r =>  if x == y then r + 1 else r) 0 fs
 part2 : (List Int, List Int) -> Int
 part2 (l1, l2) = sum $ map (\x => x * (occur x l2)) l1
 
-main : IO ()
-main = do
-  estr <- readFile "data/day1.txt"
-  str <- either (die . show) pure estr
-  putStrLn $ show $ part1 $ unzip $ parseStr str
-  putStrLn $ show $ part2 $ unzip $ parseStr str
+export
+sol1 : String -> String
+sol1 = show . part1 . unzip . parseStr
+
+export
+sol2 : String -> String
+sol2 = show . part2 . unzip . parseStr
diff --git a/src/Main.idr b/src/Main.idr
new file mode 100644
index 0000000..e2faf59
--- /dev/null
+++ b/src/Main.idr
@@ -0,0 +1,22 @@
+module Main
+
+import Day1
+import System
+import System.File
+import Data.Fin
+import Data.String
+
+runDay : Int -> String -> String
+runDay n inp = case n of
+  1 => unlines [Day1.sol1 inp, Day1.sol2 inp]
+  _ => "Not implemented yet!"
+
+main : IO ()
+main = do
+  args <- getArgs
+  digit <- maybe (die "Usage: aoc <daynumber>") pure $ getAt 1 args
+  num <- maybe (die "Usage: aoc <daynumber>") pure (parseInteger digit)
+  einp <- readFile ("./data/day" ++ (show num) ++ ".txt")
+  inp <- either (const $ die "Not implemented yet!") pure einp
+  putStrLn $ runDay num inp
+  pure ()