From d2eaf23c0d8a2117d592a4cff4ee14387f00196e Mon Sep 17 00:00:00 2001 From: Brian Chu Date: Thu, 27 Jan 2022 23:59:15 -0800 Subject: solution for day 5 --- day5.ml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 day5.ml 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); -- cgit 1.4.1-2-gfad0