summary refs log tree commit diff stats
path: root/bin
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-08-20 10:19:53 -0700
committerBrian Chu <brianmchu42@gmail.com>2022-08-20 10:19:53 -0700
commitc9a6741617eb28834674a5ef84daae4366ac4101 (patch)
treed0bf55bc68b10d3d152ddbf43d7545cd9e94ed75 /bin
parent484c4a998f9782eb0b84ec9121d6718fa6d35c1d (diff)
downloadAdventOfCode2018-c9a6741617eb28834674a5ef84daae4366ac4101.tar.gz
set up solution skeletons, driver framework, and solution for day 1
Diffstat (limited to 'bin')
-rw-r--r--bin/dune2
-rw-r--r--bin/main.ml28
2 files changed, 28 insertions, 2 deletions
diff --git a/bin/dune b/bin/dune
index c6fe6fc..40bcfe3 100644
--- a/bin/dune
+++ b/bin/dune
@@ -1,4 +1,4 @@
 (executable
  (public_name AoC2018)
  (name main)
- (libraries AoC2018))
+ (libraries AoC2018 stdio))
diff --git a/bin/main.ml b/bin/main.ml
index 7bf6048..d72fbe4 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -1 +1,27 @@
-let () = print_endline "Hello, World!"
+open AoC2018
+open Stdio
+
+let user_prompt (prompt: string): int =
+  print_string prompt;
+  flush stdout;
+  match In_channel.input_line In_channel.stdin with
+  | None -> failwith "no input given!"
+  | Some line -> int_of_string line
+  
+let load_file f =
+  let ic = open_in f in
+  let n = in_channel_length ic in
+  let s = Bytes.create n in
+  really_input ic s 0 n;
+  close_in ic;
+  (Bytes.unsafe_to_string s)
+
+let () = 
+  let day = user_prompt "which day? " in
+  let part = user_prompt "which part? " in
+    match (day, part) with
+    | (1, 1) -> load_file "inputs/day1.txt" |> Day1.part_1 |> printf "%d\n"
+    | (1, 2) -> load_file "inputs/day1.txt" |> Day1.part_2 |> printf "%d\n"
+    | _ -> printf "invalid combination\n"
+  
+