From cdbf4be6fa793ca1286604bdc2a1bb5c9e6a197a Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Mon, 1 Dec 2025 22:51:45 +0100 Subject: refactor(2025d1p1): rename files to order correctly and include part number --- 2025/ocaml/lib/application/d01p01.ml | 49 +++++++++++++++++++++++++++++++++++ 2025/ocaml/lib/application/d01p01.mli | 4 +++ 2025/ocaml/lib/application/day_1.ml | 49 ----------------------------------- 2025/ocaml/lib/application/day_1.mli | 4 --- 4 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 2025/ocaml/lib/application/d01p01.ml create mode 100644 2025/ocaml/lib/application/d01p01.mli delete mode 100644 2025/ocaml/lib/application/day_1.ml delete mode 100644 2025/ocaml/lib/application/day_1.mli (limited to '2025/ocaml/lib/application') diff --git a/2025/ocaml/lib/application/d01p01.ml b/2025/ocaml/lib/application/d01p01.ml new file mode 100644 index 0000000..75e1b17 --- /dev/null +++ b/2025/ocaml/lib/application/d01p01.ml @@ -0,0 +1,49 @@ +open Domain.D01p01 + +let rec input_to_lines input = + let lines = + String.split_on_char '\n' input |> List.filter (fun l -> l <> "") + in + pp_lines lines ; lines + +and pp_lines = function + | [] -> + () + | h :: t -> + Logs.debug (fun m -> m "Line=%s" h) ; + pp_lines t + +let parse_line line = + Scanf.sscanf line "%c%d" (fun d n -> + match d with + | 'L' -> + Dial.Left n + | 'R' -> + Dial.Right n + | _ -> + failwith "invalid direction" ) + +let lines_to_turns = + List.map (fun (l : string) -> + Logs.debug (fun m -> m "parsing %s into turn" l) ; + let turn = parse_line l in + Logs.debug (fun m -> m "%s" (Dial.pp_direction turn)) ; + turn ) + +let rec turn_aux count current = function + | [] -> + count + | h :: t -> + let current' = Dial.turn current h in + Logs.debug (fun m -> m "dial at %d" (Dial.to_int current')) ; + if Dial.to_int current' = 0 then turn_aux (count + 1) current' t + else turn_aux count current' t + +let turn current = turn_aux 0 current + +let solve input () = + let lines = input_to_lines input in + let turns = lines_to_turns lines in + let start = Dial.start in + let answer = turn start turns in + answer diff --git a/2025/ocaml/lib/application/d01p01.mli b/2025/ocaml/lib/application/d01p01.mli new file mode 100644 index 0000000..73631f1 --- /dev/null +++ b/2025/ocaml/lib/application/d01p01.mli @@ -0,0 +1,4 @@ +val solve : string -> unit -> int +(** [solve input ()] is the solution for the first day of advent of code 2025 for [input]. + The solution for an empty input is [Domain.Day_1.Dial.(to_int start)]. + Requires: [input] to be a multiline string using `\n` as it's line separator. *) diff --git a/2025/ocaml/lib/application/day_1.ml b/2025/ocaml/lib/application/day_1.ml deleted file mode 100644 index bc0d5cc..0000000 --- a/2025/ocaml/lib/application/day_1.ml +++ /dev/null @@ -1,49 +0,0 @@ -open Domain.Day_1 - -let rec input_to_lines input = - let lines = - String.split_on_char '\n' input |> List.filter (fun l -> l <> "") - in - pp_lines lines ; lines - -and pp_lines = function - | [] -> - () - | h :: t -> - Logs.debug (fun m -> m "Line=%s" h) ; - pp_lines t - -let parse_line line = - Scanf.sscanf line "%c%d" (fun d n -> - match d with - | 'L' -> - Dial.Left n - | 'R' -> - Dial.Right n - | _ -> - failwith "invalid direction" ) - -let lines_to_turns = - List.map (fun (l : string) -> - Logs.debug (fun m -> m "parsing %s into turn" l) ; - let turn = parse_line l in - Logs.debug (fun m -> m "%s" (Dial.pp_direction turn)) ; - turn ) - -let rec turn_aux count current = function - | [] -> - count - | h :: t -> - let current' = Dial.turn current h in - Logs.debug (fun m -> m "dial at %d" (Dial.to_int current')) ; - if Dial.to_int current' = 0 then turn_aux (count + 1) current' t - else turn_aux count current' t - -let turn current = turn_aux 0 current - -let solve input () = - let lines = input_to_lines input in - let turns = lines_to_turns lines in - let start = Dial.start in - let answer = turn start turns in - answer diff --git a/2025/ocaml/lib/application/day_1.mli b/2025/ocaml/lib/application/day_1.mli deleted file mode 100644 index 73631f1..0000000 --- a/2025/ocaml/lib/application/day_1.mli +++ /dev/null @@ -1,4 +0,0 @@ -val solve : string -> unit -> int -(** [solve input ()] is the solution for the first day of advent of code 2025 for [input]. - The solution for an empty input is [Domain.Day_1.Dial.(to_int start)]. - Requires: [input] to be a multiline string using `\n` as it's line separator. *) -- cgit v1.2.3