summary refs log tree commit diff stats
path: root/day5.ml
diff options
context:
space:
mode:
Diffstat (limited to 'day5.ml')
-rw-r--r--day5.ml26
1 files changed, 26 insertions, 0 deletions
diff --git a/day5.ml b/day5.ml
new file mode 100644
index 0000000..e0e1aa0
--- /dev/null
+++ b/day5.ml
@@ -0,0 +1,26 @@
+#use "topfind";;
+#thread;;
+#require "core";;
+#require "stdio";;
+
+open Core
+open Stdio
+
+let program = In_channel.read_lines "day5.txt"
+              |> List.map ~f:(fun x -> String.strip x |> int_of_string)
+
+let execute insts part2 =
+  let rec helper insts index steps part2 =
+    if 0 > index || index > (Array.length insts - 1) then steps
+    else
+      let jump = insts.(index) in
+      insts.(index) <- (if part2 && jump >= 3 then jump - 1 else jump + 1);
+      helper insts (index + jump) (steps + 1) part2 in
+  helper insts 0 0 part2
+
+let () =
+  let program1 = Array.of_list program in
+  Printf.printf "%d\n" (execute program1 false);
+
+  let program2 = Array.of_list program in
+  Printf.printf "%d\n" (execute program2 true);