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)