summary refs log tree commit diff stats
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
parent484c4a998f9782eb0b84ec9121d6718fa6d35c1d (diff)
downloadAdventOfCode2018-c9a6741617eb28834674a5ef84daae4366ac4101.tar.gz
set up solution skeletons, driver framework, and solution for day 1
-rw-r--r--.gitignore2
-rw-r--r--AoC2018.opam28
-rw-r--r--bin/dune2
-rw-r--r--bin/main.ml28
-rw-r--r--dune-project18
-rw-r--r--lib/day1.ml25
-rw-r--r--lib/day10.ml7
-rw-r--r--lib/day11.ml7
-rw-r--r--lib/day12.ml7
-rw-r--r--lib/day13.ml7
-rw-r--r--lib/day14.ml7
-rw-r--r--lib/day15.ml7
-rw-r--r--lib/day16.ml7
-rw-r--r--lib/day17.ml7
-rw-r--r--lib/day18.ml7
-rw-r--r--lib/day19.ml7
-rw-r--r--lib/day2.ml7
-rw-r--r--lib/day20.ml7
-rw-r--r--lib/day21.ml7
-rw-r--r--lib/day22.ml7
-rw-r--r--lib/day23.ml7
-rw-r--r--lib/day24.ml7
-rw-r--r--lib/day25.ml7
-rw-r--r--lib/day3.ml7
-rw-r--r--lib/day4.ml7
-rw-r--r--lib/day5.ml7
-rw-r--r--lib/day6.ml7
-rw-r--r--lib/day7.ml7
-rw-r--r--lib/day8.ml7
-rw-r--r--lib/day9.ml7
-rw-r--r--lib/dune3
31 files changed, 259 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..169d1a6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+_build
+inputs
\ No newline at end of file
diff --git a/AoC2018.opam b/AoC2018.opam
index e69de29..2660b40 100644
--- a/AoC2018.opam
+++ b/AoC2018.opam
@@ -0,0 +1,28 @@
+# This file is generated by dune, edit dune-project instead
+opam-version: "2.0"
+synopsis: "Solutions for Advent of Code 2018"
+authors: ["Brian Chu"]
+license: "GPL-3+"
+depends: [
+  "ocaml"
+  "dune" {>= "3.4"}
+  "stdio"
+  "core"
+  "odoc" {with-doc}
+]
+build: [
+  ["dune" "subst"] {dev}
+  [
+    "dune"
+    "build"
+    "-p"
+    name
+    "-j"
+    jobs
+    "@install"
+    "@runtest" {with-test}
+    "@doc" {with-doc}
+  ]
+]
+dev-repo:
+  "https://git.tilde.institute/brinoleum/AdventOfCode/AdventOfCode2018.git"
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"
+  
+
diff --git a/dune-project b/dune-project
index ce69210..7e3a5d2 100644
--- a/dune-project
+++ b/dune-project
@@ -5,22 +5,16 @@
 (generate_opam_files true)
 
 (source
- (github username/reponame))
+ (uri https://git.tilde.institute/brinoleum/AdventOfCode/AdventOfCode2018.git))
 
-(authors "Author Name")
+(authors "Brian Chu")
 
-(maintainers "Maintainer Name")
-
-(license LICENSE)
-
-(documentation https://url/to/documentation)
+(license GPL-3+)
 
 (package
  (name AoC2018)
- (synopsis "A short synopsis")
- (description "A longer description")
- (depends ocaml dune)
- (tags
-  (topics "to describe" your project)))
+ (synopsis "Solutions for Advent of Code 2018")
+ (depends ocaml dune stdio core)
+)
 
 ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project
diff --git a/lib/day1.ml b/lib/day1.ml
new file mode 100644
index 0000000..748b529
--- /dev/null
+++ b/lib/day1.ml
@@ -0,0 +1,25 @@
+open Core
+
+(* Take text input from file and process accordingly *)
+let process_input input = String.split_lines input |> List.map ~f:int_of_string
+
+(* Fill in solutions for each part *)
+let part_1 input =
+  let freq_changes = process_input input in
+  List.fold freq_changes ~init:0 ~f:(+)
+
+let part_2 input =
+  let freq_changes = process_input input |> Sequence.cycle_list_exn in
+  let counter = Hashtbl.create (module Int) in
+  let increment key = Hashtbl.update_and_return counter key 
+    ~f:(function
+        | Some num -> num + 1
+        | None -> 1) in
+  Sequence.fold_until freq_changes ~init:0 
+    ~f:(fun sum freq ->
+      if (increment (sum + freq)) = 2
+      then
+        Stop (sum + freq)
+      else
+        Continue (sum + freq))
+    ~finish:(fun sum -> sum)
\ No newline at end of file
diff --git a/lib/day10.ml b/lib/day10.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day10.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day11.ml b/lib/day11.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day11.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day12.ml b/lib/day12.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day12.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day13.ml b/lib/day13.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day13.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day14.ml b/lib/day14.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day14.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day15.ml b/lib/day15.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day15.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day16.ml b/lib/day16.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day16.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day17.ml b/lib/day17.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day17.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day18.ml b/lib/day18.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day18.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day19.ml b/lib/day19.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day19.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day2.ml b/lib/day2.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day2.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day20.ml b/lib/day20.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day20.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day21.ml b/lib/day21.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day21.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day22.ml b/lib/day22.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day22.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day23.ml b/lib/day23.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day23.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day24.ml b/lib/day24.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day24.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day25.ml b/lib/day25.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day25.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day3.ml b/lib/day3.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day3.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day4.ml b/lib/day4.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day4.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day5.ml b/lib/day5.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day5.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day6.ml b/lib/day6.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day6.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day7.ml b/lib/day7.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day7.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day8.ml b/lib/day8.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day8.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/day9.ml b/lib/day9.ml
new file mode 100644
index 0000000..7c5e310
--- /dev/null
+++ b/lib/day9.ml
@@ -0,0 +1,7 @@
+(* Take text input from file and process accordingly *)
+let process_input _input = ()
+
+(* Fill in solutions for each part *)
+let part_1 _input = ()
+
+let part_2 _input = ()
diff --git a/lib/dune b/lib/dune
index 050d705..932cc41 100644
--- a/lib/dune
+++ b/lib/dune
@@ -1,2 +1,3 @@
 (library
- (name AoC2018))
+ (name AoC2018)
+ (libraries stdio core))
\ No newline at end of file