diff options
author | Brian Chu <brianmchu42@gmail.com> | 2022-01-27 23:59:15 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2022-01-27 23:59:15 -0800 |
commit | d2eaf23c0d8a2117d592a4cff4ee14387f00196e (patch) | |
tree | 8bf638ab8b3d0d7c91030b9f0115ecac4a78922e | |
parent | facc9b10d3df43354e684882505fd07a3bc0985f (diff) | |
download | AdventOfCode2017-d2eaf23c0d8a2117d592a4cff4ee14387f00196e.tar.gz |
solution for day 5
-rw-r--r-- | day5.ml | 26 |
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); |