diff options
| author | DJ O'Leary <dijitol@proton.me> | 2026-06-27 00:11:43 +0200 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2026-06-27 00:11:43 +0200 |
| commit | 976048a85403fbb0751c34fa42703a3c47f6e918 (patch) | |
| tree | 46e321d8120c45e318ead66f60165b0b854c85a1 /ocaml/lib/application/d04p01.ml | |
| parent | 6d8fb621d1e93b83786890d6d9cb6f0d8defa8ae (diff) | |
refactor!: change repo directory structure for ocaml
Diffstat (limited to 'ocaml/lib/application/d04p01.ml')
| -rw-r--r-- | ocaml/lib/application/d04p01.ml | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/ocaml/lib/application/d04p01.ml b/ocaml/lib/application/d04p01.ml deleted file mode 100644 index 7c69de4..0000000 --- a/ocaml/lib/application/d04p01.ml +++ /dev/null @@ -1,48 +0,0 @@ -open Domain - -let err_empty_input = "input is empty" - -let rec solve input () = - if input = "" then Error err_empty_input - else - let matrix = Matrix.M.of_string input in - let count_paper lst = List.length @@ List.filter (fun c -> c <> ".") lst in - let accessible_rolls_of_paper = ref 0 in - for y = 0 to Array.length matrix - 1 do - for x = 0 to Array.length matrix.(y) - 1 do - if matrix.(y).(x) = "." then () - else - let neighbour_coords = Matrix.M.get_valid_neighbours matrix x y in - let neighbours = - List.map - (fun (x', y') -> Matrix.M.get matrix x' y') - neighbour_coords - in - let paper_count = count_paper neighbours in - let is_accessible = paper_count < 4 in - if is_accessible then - accessible_rolls_of_paper := !accessible_rolls_of_paper + 1 ; - print_iteration_debug_msg x y neighbour_coords neighbours paper_count - is_accessible - done - done ; - Ok !accessible_rolls_of_paper - -and print_iteration_debug_msg x y neighbour_coords neighbours paper_count - is_accessible = - Logs.debug (fun m -> - m - "coords=(%d,%d) neighbour_coords=[%s] neighbours=[%s] paper=%d \ - is_accessible=%B" - x y - (List.fold_left - (fun acc (x, y) -> - if acc = "" then - " (" ^ string_of_int x ^ "," ^ string_of_int y ^ "); " - else acc ^ "(" ^ string_of_int x ^ "," ^ string_of_int y ^ "); " ) - "" neighbour_coords ) - (List.fold_left - (fun acc neighbour -> - if acc = "" then " " ^ neighbour ^ "; " else acc ^ neighbour ^ "; " ) - "" neighbours ) - paper_count is_accessible ) |
