#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);