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 | |
| parent | 6d8fb621d1e93b83786890d6d9cb6f0d8defa8ae (diff) | |
refactor!: change repo directory structure for ocaml
Diffstat (limited to 'ocaml')
| -rw-r--r-- | ocaml/CODEOWNERS | 1 | ||||
| -rw-r--r-- | ocaml/CONTRIBUTING.md | 5 | ||||
| -rw-r--r-- | ocaml/LICENSE | 25 | ||||
| -rw-r--r-- | ocaml/README.md | 55 | ||||
| -rw-r--r-- | ocaml/Taskfile.yaml | 5 | ||||
| -rw-r--r-- | ocaml/advent_of_code.opam | 7 | ||||
| -rw-r--r-- | ocaml/bin/dune | 10 | ||||
| -rw-r--r-- | ocaml/bin/main.ml | 59 | ||||
| -rw-r--r-- | ocaml/dune-project | 6 | ||||
| -rw-r--r-- | ocaml/flake.nix | 3 | ||||
| -rw-r--r-- | ocaml/lib/application/d05p01.ml | 3 | ||||
| -rw-r--r-- | ocaml/lib/application/d05p01.mli | 4 | ||||
| -rw-r--r-- | ocaml/lib/infrastructure/dune | 15 | ||||
| -rw-r--r-- | ocaml/lib/infrastructure/file.mli | 3 | ||||
| -rw-r--r-- | ocaml/lib/presentation/cli.ml | 62 | ||||
| -rw-r--r-- | ocaml/lib/presentation/dune | 16 | ||||
| -rw-r--r-- | ocaml/lib/shared/dune (renamed from ocaml/lib/domain/dune) | 9 | ||||
| -rw-r--r-- | ocaml/lib/shared/file.ml (renamed from ocaml/lib/infrastructure/file.ml) | 2 | ||||
| -rw-r--r-- | ocaml/lib/shared/matrix.ml (renamed from ocaml/lib/domain/matrix.ml) | 0 | ||||
| -rw-r--r-- | ocaml/lib/shared/parser.ml (renamed from ocaml/lib/application/parser.ml) | 0 | ||||
| -rw-r--r-- | ocaml/lib/shared/range.ml (renamed from ocaml/lib/domain/range.ml) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part01/dial.ml (renamed from ocaml/lib/domain/d01p01.ml) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part01/solver.ml (renamed from ocaml/lib/application/d01p01.ml) | 2 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part01/solver.mli (renamed from ocaml/lib/application/d01p01.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part02/dial.ml (renamed from ocaml/lib/domain/d01p02.ml) | 27 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part02/solver.ml (renamed from ocaml/lib/application/d01p02.ml) | 3 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part02/solver.mli (renamed from ocaml/lib/application/d01p02.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day01/part02/turner.ml | 28 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/id.ml | 16 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/id.mli (renamed from ocaml/lib/domain/d02p01.mli) | 14 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/range.ml (renamed from ocaml/lib/domain/d02p02.ml) | 13 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/range.mli | 15 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/solver.ml (renamed from ocaml/lib/application/d02p01.ml) | 3 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part01/solver.mli (renamed from ocaml/lib/application/d02p01.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/id.ml | 12 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/id.mli (renamed from ocaml/lib/domain/d02p02.mli) | 14 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/range.ml (renamed from ocaml/lib/domain/d02p01.ml) | 17 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/range.mli | 15 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/solver.ml (renamed from ocaml/lib/application/d02p02.ml) | 3 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day02/part02/solver.mli (renamed from ocaml/lib/application/d02p02.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/battery.ml | 13 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/battery.mli | 13 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/battery_bank.ml (renamed from ocaml/lib/domain/d03p01.ml) | 43 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/battery_bank.mli | 18 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/solver.ml (renamed from ocaml/lib/application/d03p01.ml) | 2 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part01/solver.mli (renamed from ocaml/lib/application/d03p01.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/battery.ml | 25 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/battery.mli | 13 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/battery_bank.ml (renamed from ocaml/lib/domain/d03p02.ml) | 43 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/battery_bank.mli | 18 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/solver.ml (renamed from ocaml/lib/application/d03p02.ml) | 2 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day03/part02/solver.mli (renamed from ocaml/lib/application/d03p02.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day04/part01/solver.ml (renamed from ocaml/lib/application/d04p01.ml) | 10 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day04/part01/solver.mli (renamed from ocaml/lib/application/d04p01.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day04/part02/solver.ml (renamed from ocaml/lib/application/d04p02.ml) | 14 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day04/part02/solver.mli (renamed from ocaml/lib/application/d04p02.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day06/part01/solver.ml (renamed from ocaml/lib/application/d06p01.ml) | 4 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day06/part01/solver.mli (renamed from ocaml/lib/application/d06p01.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day06/part02/solver.ml (renamed from ocaml/lib/application/d06p02.ml) | 4 | ||||
| -rw-r--r-- | ocaml/lib/year2025/day06/part02/solver.mli (renamed from ocaml/lib/application/d06p02.mli) | 0 | ||||
| -rw-r--r-- | ocaml/lib/year2025/dune (renamed from ocaml/lib/application/dune) | 10 | ||||
| -rw-r--r-- | ocaml/test/application/dune | 9 | ||||
| -rw-r--r-- | ocaml/test/infrastructure/dune | 8 | ||||
| -rw-r--r-- | ocaml/test/infrastructure/test_example.ml | 0 | ||||
| -rw-r--r-- | ocaml/test/presentation/dune | 11 | ||||
| -rw-r--r-- | ocaml/test/presentation/test_example.ml | 0 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part01/dune | 11 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part01/test_dial.ml (renamed from ocaml/test/domain/test_d01p01.ml) | 2 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part01/test_solver.ml (renamed from ocaml/test/application/test_d01p01.ml) | 2 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part02/dune | 11 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part02/test_dial.ml (renamed from ocaml/test/domain/test_d01p02.ml) | 3 | ||||
| -rw-r--r-- | ocaml/test/year2025/day01/part02/test_solver.ml (renamed from ocaml/test/application/test_d01p02.ml) | 2 | ||||
| -rw-r--r-- | ocaml/test/year2025/day03/part01/dune | 10 | ||||
| -rw-r--r-- | ocaml/test/year2025/day03/part01/test_battery_bank.ml (renamed from ocaml/test/domain/test_d03p01.ml) | 2 | ||||
| -rw-r--r-- | ocaml/test/year2025/day04/part01/dune (renamed from ocaml/test/domain/dune) | 7 | ||||
| -rw-r--r-- | ocaml/test/year2025/day04/part01/test_solver.ml (renamed from ocaml/test/application/test_d04p01.ml) | 2 |
76 files changed, 348 insertions, 436 deletions
diff --git a/ocaml/CODEOWNERS b/ocaml/CODEOWNERS deleted file mode 100644 index 66c50a2..0000000 --- a/ocaml/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @djoleary diff --git a/ocaml/CONTRIBUTING.md b/ocaml/CONTRIBUTING.md deleted file mode 100644 index 832b94b..0000000 --- a/ocaml/CONTRIBUTING.md +++ /dev/null @@ -1,5 +0,0 @@ -# Contributing - -## Commit Messages - -We use conventional commits for all commit messages. See <https://www.conventionalcommits.org/en/v1.0.0/> diff --git a/ocaml/LICENSE b/ocaml/LICENSE deleted file mode 100644 index 1e9858b..0000000 --- a/ocaml/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to <https://unlicense.org> - diff --git a/ocaml/README.md b/ocaml/README.md index 772c76b..7d64eb8 100644 --- a/ocaml/README.md +++ b/ocaml/README.md @@ -1,54 +1 @@ -# OCaml Template - -This is a template for OCaml projects. - -## Quick Start - -1. Fork this repository -2. Rename the repository to your project name -3. Replace all instances of `advent_of_code` with your project name, both in files and filenames themselves. - -## Project Structure - -```txt -. -├── _build # build outputs -├── bin # program entry points -├── docs # documentation -├── lib # public modules -├── test # tests -├── .editorconfig -├── .envrc -├── .gitignore -├── .ocamlformat # ocamlformat configuration -├── CODEOWNERS -├── CONTRIBUTING.md -├── LICENSE -├── README.md -├── Taskfile.yml # task runner configuration similar to make -├── dune-project # dune project configuration -├── flake.lock -├── flake.nix # nix flake configuration -├── advent_of_code.install # autogenerated install script -└── advent_of_code.opam # autogenerated project description -``` - -## Tools - -- [task](https://taskfile.dev/) -- [dune](https://dune.build/) -- [opam](https://opam.ocaml.org/) -- [ocamlformat](https://ocaml.org/p/ocamlformat/latest/doc/index.html) -- [odoc](https://ocaml.github.io/odoc/odoc/index.html) -- [alchotest](https://github.com/mirage/alcotest) -- [bisect_ppx](https://github.com/aantron/bisect_ppx) -- [ocaml-lsp](https://github.com/ocaml/ocaml-lsp) -- [earlybird](https://github.com/ocaml-lsp/earlybird) -- [findlib](https://github.com/ocaml/ocamlfind) -- [re2](https://github.com/janestreet/re2) -- [fmt](https://erratique.ch/software/fmt) -- [cmdliner](https://erratique.ch/software/cmdliner) - -## License - -This project is licensed under the [Unlicense](https://unlicense.org/). +# Advent of Code: OCaml diff --git a/ocaml/Taskfile.yaml b/ocaml/Taskfile.yaml index 4a4cbe2..fdc1a1d 100644 --- a/ocaml/Taskfile.yaml +++ b/ocaml/Taskfile.yaml @@ -24,6 +24,7 @@ tasks: - task: build cmds: - cmd: dune runtest {{.CLI_ARGS}} + silent: true test:watch: desc: Continuously runs the tests @@ -62,6 +63,7 @@ tasks: - SUITE cmds: - cmd: dune exec {{.SUITE}}.exe -- {{.CLI_ARGS}} + silent: true build: desc: Builds the project @@ -69,6 +71,7 @@ tasks: - command -v dune cmds: - cmd: dune build + silent: true build:watch: desc: Builds the project when files change @@ -92,6 +95,7 @@ tasks: - task: build cmds: - cmd: dune exec -- ./bin/main.exe {{.CLI_ARGS}} + silent: true repl: desc: Opens a REPL for the project @@ -101,3 +105,4 @@ tasks: - command -v utop cmds: - cmd: dune utop + silent: true diff --git a/ocaml/advent_of_code.opam b/ocaml/advent_of_code.opam index 103f2ce..3838b60 100644 --- a/ocaml/advent_of_code.opam +++ b/ocaml/advent_of_code.opam @@ -1,14 +1,13 @@ # This file is generated by dune, edit dune-project instead opam-version: "2.0" -synopsis: "advent of code solutions for 2025" -description: - "project aiming to solve the advent of code puzzles released for 2025" +synopsis: "advent of code solutions" +description: "project aiming to solve the advent of code puzzles" maintainer: ["DJ O'Leary <dijitol@proton.me>"] authors: ["DJ O'Leary <dijitol@proton.me>"] license: "Unlicense" tags: ["Advent of Code"] homepage: "https://github.com/djoleary/advent_of_code" -doc: "https://github.com/djoleary/advent_of_code/2025/ocaml/docs/index.html" +doc: "https://codeberg.org/dijitol/advent_of_code/ocaml/docs/index.html" bug-reports: "https://github.com/djoleary/advent_of_code/issues" depends: [ "dune" {>= "3.20"} diff --git a/ocaml/bin/dune b/ocaml/bin/dune index 0f6768d..f267518 100644 --- a/ocaml/bin/dune +++ b/ocaml/bin/dune @@ -2,10 +2,12 @@ (public_name advent_of_code) (name main) (libraries - domain - application - infrastructure - presentation + shared + year2025 + cmdliner + fmt + fmt.cli + fmt.tty logs logs.fmt) (modes byte exe)) diff --git a/ocaml/bin/main.ml b/ocaml/bin/main.ml index cbfe6d2..4ed5d83 100644 --- a/ocaml/bin/main.ml +++ b/ocaml/bin/main.ml @@ -5,12 +5,69 @@ let env_log_level = | Some lvl -> ( match Logs.level_of_string lvl with Error _ -> None | Ok v -> v ) +let run_solver name solver filepath = + let content = Shared.File.read filepath in + match solver content () with + | Error msg -> + Logs.app (fun m -> m "[%s] Err=%s" name msg) + | Ok answer -> + Logs.app (fun m -> m "[%s] ANSWER=%d" name answer) + +let run_day _ = function + | 1 -> + let filepath = "../.input/2025/day_01.txt" in + run_solver "D01P01" Year2025.Day01.Part01.Solver.solve filepath ; + run_solver "D01P02" Year2025.Day01.Part02.Solver.solve filepath ; + 0 + | 2 -> + let filepath = "../.input/2025/day_02.txt" in + run_solver "D02P01" Year2025.Day02.Part01.Solver.solve filepath ; + run_solver "D02P02" Year2025.Day02.Part02.Solver.solve filepath ; + 0 + | 3 -> + let filepath = "../.input/2025/day_03.txt" in + run_solver "D03P01" Year2025.Day03.Part01.Solver.solve filepath ; + run_solver "D03P02" Year2025.Day03.Part02.Solver.solve filepath ; + 0 + | 4 -> + let filepath = "../.input/2025/day_04.txt" in + run_solver "D04P01" Year2025.Day04.Part01.Solver.solve filepath ; + run_solver "D04P02" Year2025.Day04.Part02.Solver.solve filepath ; + 0 + | 6 -> + let filepath = "../.input/2025/day_06.txt" in + run_solver "D06P01" Year2025.Day06.Part01.Solver.solve filepath ; + run_solver "D06P02" Year2025.Day06.Part02.Solver.solve filepath ; + 0 + | _ -> + failwith "day not implemented" + +(* Command line interface *) + +open Cmdliner + +let setup_log style_renderer = Fmt_tty.setup_std_outputs ?style_renderer () + +let setup_log_t = Term.(const setup_log $ Fmt_cli.style_renderer ()) + +let day_arg = + let doc = "Day to run. MUST be in range of 1-12." in + Arg.(value & pos 0 int 1 & info [] ~docv:"DAY" ~doc) + +let day_t = Term.(const run_day $ setup_log_t $ day_arg) + +let cmd = + let info = Cmd.info "aoc" ~version:"0.1.0" in + Cmd.v info day_t + +let run () = Cmd.eval' cmd + let main () = let log_level = env_log_level in Logs.set_level log_level ; Logs.set_reporter (Logs_fmt.reporter ()) ; Logs.info (fun m -> m "Started application with LOG_LEVEL=%s" (Logs.level_to_string log_level) ) ; - Presentation.Cli.run () + run () let () = if !Sys.interactive then () else exit (main ()) diff --git a/ocaml/dune-project b/ocaml/dune-project index 731f4b5..46b1de2 100644 --- a/ocaml/dune-project +++ b/ocaml/dune-project @@ -13,12 +13,12 @@ (license Unlicense) -(documentation https://github.com/djoleary/advent_of_code/2025/ocaml/docs/index.html) +(documentation https://codeberg.org/dijitol/advent_of_code/ocaml/docs/index.html) (package (name advent_of_code) - (synopsis "advent of code solutions for 2025") - (description "project aiming to solve the advent of code puzzles released for 2025") + (synopsis "advent of code solutions") + (description "project aiming to solve the advent of code puzzles") (depends (ocaml (>= 5.2)) (ppx_deriving :build) diff --git a/ocaml/flake.nix b/ocaml/flake.nix index 54d7b3f..0176014 100644 --- a/ocaml/flake.nix +++ b/ocaml/flake.nix @@ -42,11 +42,10 @@ ]; sysTools = with pkgs; [ go-task - gh ]; in pkgs.mkShell { buildInputs = ocamlPackages ++ sysTools; }; }; -}
\ No newline at end of file +} diff --git a/ocaml/lib/application/d05p01.ml b/ocaml/lib/application/d05p01.ml deleted file mode 100644 index 4bf79ab..0000000 --- a/ocaml/lib/application/d05p01.ml +++ /dev/null @@ -1,3 +0,0 @@ -let err_empty_input = "input is empty" - -let solve input () = if input = "" then Error err_empty_input else Ok 0 diff --git a/ocaml/lib/application/d05p01.mli b/ocaml/lib/application/d05p01.mli deleted file mode 100644 index 85c3dd5..0000000 --- a/ocaml/lib/application/d05p01.mli +++ /dev/null @@ -1,4 +0,0 @@ -val solve : string -> unit -> (int, string) result -(** [solve input ()] is the solution for the first part of the five day of advent of code 2025 for [input]. - The solution for an empty input is [Error msg]. - Requires: [input] to be a string. *) diff --git a/ocaml/lib/infrastructure/dune b/ocaml/lib/infrastructure/dune deleted file mode 100644 index b9d250f..0000000 --- a/ocaml/lib/infrastructure/dune +++ /dev/null @@ -1,15 +0,0 @@ -(library - (name infrastructure) - (libraries - application - domain - fmt - logs) - (inline_tests) - (preprocess - (pps - ppx_deriving.show - ppx_deriving.eq - ppx_deriving.ord - ppx_inline_test - ppx_expect))) diff --git a/ocaml/lib/infrastructure/file.mli b/ocaml/lib/infrastructure/file.mli deleted file mode 100644 index 17d4495..0000000 --- a/ocaml/lib/infrastructure/file.mli +++ /dev/null @@ -1,3 +0,0 @@ -val read : string -> string -(** [read filename] is the contents of [filename] as a string. - The empty string is returned if [filename] does not exist. *) diff --git a/ocaml/lib/presentation/cli.ml b/ocaml/lib/presentation/cli.ml deleted file mode 100644 index 7864e7f..0000000 --- a/ocaml/lib/presentation/cli.ml +++ /dev/null @@ -1,62 +0,0 @@ -(* Business logic behind CLI *) - -let run_solver name solver filepath = - let content = Infrastructure.File.read filepath in - match solver content () with - | Error msg -> - Logs.app (fun m -> m "[%s] Err=%s" name msg) - | Ok answer -> - Logs.app (fun m -> m "[%s] ANSWER=%d" name answer) - -let run_day _ = function - | 1 -> - let filepath = "../_input/day_01.txt" in - run_solver "D01P01" Application.D01p01.solve filepath ; - run_solver "D01P02" Application.D01p02.solve filepath ; - 0 - | 2 -> - let filepath = "../_input/day_02.txt" in - run_solver "D02P01" Application.D02p01.solve filepath ; - run_solver "D02P02" Application.D02p02.solve filepath ; - 0 - | 3 -> - let filepath = "../_input/day_03.txt" in - run_solver "D03P01" Application.D03p01.solve filepath ; - run_solver "D03P02" Application.D03p02.solve filepath ; - 0 - | 4 -> - let filepath = "../_input/day_04.txt" in - run_solver "D04P01" Application.D04p01.solve filepath ; - run_solver "D04P02" Application.D04p02.solve filepath ; - 0 - | 5 -> - let filepath = "../_input/day_05.txt" in - run_solver "D05P01" Application.D05p01.solve filepath ; - 0 - | 6 -> - let filepath = "../_input/day_06.txt" in - run_solver "D06P01" Application.D06p01.solve filepath ; - run_solver "D06P02" Application.D06p02.solve filepath ; - 0 - | _ -> - failwith "day not implemented" - -(* Command line interface *) - -open Cmdliner - -let setup_log style_renderer = Fmt_tty.setup_std_outputs ?style_renderer () - -let setup_log_t = Term.(const setup_log $ Fmt_cli.style_renderer ()) - -let day_arg = - let doc = "Day to run. MUST be in range of 1-12." in - Arg.(value & pos 0 int 1 & info [] ~docv:"DAY" ~doc) - -let day_t = Term.(const run_day $ setup_log_t $ day_arg) - -let cmd = - let info = Cmd.info "aoc" ~version:"0.1.0" in - Cmd.v info day_t - -let run () = Cmd.eval' cmd diff --git a/ocaml/lib/presentation/dune b/ocaml/lib/presentation/dune deleted file mode 100644 index ae1fcb1..0000000 --- a/ocaml/lib/presentation/dune +++ /dev/null @@ -1,16 +0,0 @@ -(library - (name presentation) - (libraries - application - domain - infrastructure - cmdliner - fmt.cli - fmt.tty) - (inline_tests) - (preprocess - (pps - ppx_deriving.show - ppx_deriving.eq - ppx_deriving.ord - ppx_expect))) diff --git a/ocaml/lib/domain/dune b/ocaml/lib/shared/dune index 5b13d31..f71a5fe 100644 --- a/ocaml/lib/domain/dune +++ b/ocaml/lib/shared/dune @@ -1,13 +1,10 @@ (library - (name domain) + (name shared) (inline_tests) - (libraries - fmt - logs) (preprocess (pps ppx_deriving.show ppx_deriving.eq ppx_deriving.ord - ppx_inline_test - ppx_expect))) + ppx_expect + ppx_inline_test))) diff --git a/ocaml/lib/infrastructure/file.ml b/ocaml/lib/shared/file.ml index 3b49c01..74b5abc 100644 --- a/ocaml/lib/infrastructure/file.ml +++ b/ocaml/lib/shared/file.ml @@ -1,3 +1,5 @@ +(** [read filename] is the contents of [filename] as a string. + The empty string is returned if [filename] does not exist. *) let read filename = let chan = In_channel.open_text filename in let content = In_channel.input_all chan in diff --git a/ocaml/lib/domain/matrix.ml b/ocaml/lib/shared/matrix.ml index fdf476f..fdf476f 100644 --- a/ocaml/lib/domain/matrix.ml +++ b/ocaml/lib/shared/matrix.ml diff --git a/ocaml/lib/application/parser.ml b/ocaml/lib/shared/parser.ml index 099900b..099900b 100644 --- a/ocaml/lib/application/parser.ml +++ b/ocaml/lib/shared/parser.ml diff --git a/ocaml/lib/domain/range.ml b/ocaml/lib/shared/range.ml index a1bdc00..a1bdc00 100644 --- a/ocaml/lib/domain/range.ml +++ b/ocaml/lib/shared/range.ml diff --git a/ocaml/lib/domain/d01p01.ml b/ocaml/lib/year2025/day01/part01/dial.ml index 6b531f4..6b531f4 100644 --- a/ocaml/lib/domain/d01p01.ml +++ b/ocaml/lib/year2025/day01/part01/dial.ml diff --git a/ocaml/lib/application/d01p01.ml b/ocaml/lib/year2025/day01/part01/solver.ml index 206e757..f4f0dde 100644 --- a/ocaml/lib/application/d01p01.ml +++ b/ocaml/lib/year2025/day01/part01/solver.ml @@ -1,4 +1,4 @@ -open Domain.D01p01 +open Dial let err_empty_input = "input is empty" diff --git a/ocaml/lib/application/d01p01.mli b/ocaml/lib/year2025/day01/part01/solver.mli index 2eecf19..2eecf19 100644 --- a/ocaml/lib/application/d01p01.mli +++ b/ocaml/lib/year2025/day01/part01/solver.mli diff --git a/ocaml/lib/domain/d01p02.ml b/ocaml/lib/year2025/day01/part02/dial.ml index f71e965..e061d6d 100644 --- a/ocaml/lib/domain/d01p02.ml +++ b/ocaml/lib/year2025/day01/part02/dial.ml @@ -66,30 +66,3 @@ end = struct | Right n -> "Right " ^ string_of_int n end - -module Turner : sig - val turn : Dial.t -> int -> Dial.direction -> Dial.t * int - (** [turn dial direction] is the new state of the dial after turning [direction] on [dial] *) -end = struct - (** [turn dial direction] is the new state of the dial after turning [direction] on [dial]. - Raises: [dial_out_of_range] if the dial is moved to an invalid state. *) - let rec turn dial zero_count direction = - let open Dial in - match direction with - | Left 0 -> - (dial, zero_count) - | Left n -> - let dial' = prev dial in - let zero_count' = - if Dial.is_zero dial' then zero_count + 1 else zero_count - in - turn dial' zero_count' (Left (n - 1)) - | Right 0 -> - (dial, zero_count) - | Right n -> - let dial' = next dial in - let zero_count' = - if Dial.is_zero dial' then zero_count + 1 else zero_count - in - turn dial' zero_count' (Right (n - 1)) -end diff --git a/ocaml/lib/application/d01p02.ml b/ocaml/lib/year2025/day01/part02/solver.ml index 7910486..452209f 100644 --- a/ocaml/lib/application/d01p02.ml +++ b/ocaml/lib/year2025/day01/part02/solver.ml @@ -1,4 +1,5 @@ -open Domain.D01p02 +open Dial +open Turner let err_empty_input = "input is empty" diff --git a/ocaml/lib/application/d01p02.mli b/ocaml/lib/year2025/day01/part02/solver.mli index 9e9a2f2..9e9a2f2 100644 --- a/ocaml/lib/application/d01p02.mli +++ b/ocaml/lib/year2025/day01/part02/solver.mli diff --git a/ocaml/lib/year2025/day01/part02/turner.ml b/ocaml/lib/year2025/day01/part02/turner.ml new file mode 100644 index 0000000..7477093 --- /dev/null +++ b/ocaml/lib/year2025/day01/part02/turner.ml @@ -0,0 +1,28 @@ +open Dial + +module Turner : sig + val turn : Dial.t -> int -> Dial.direction -> Dial.t * int + (** [turn dial direction] is the new state of the dial after turning [direction] on [dial] *) +end = struct + (** [turn dial direction] is the new state of the dial after turning [direction] on [dial]. + Raises: [dial_out_of_range] if the dial is moved to an invalid state. *) + let rec turn dial zero_count direction = + let open Dial in + match direction with + | Left 0 -> + (dial, zero_count) + | Left n -> + let dial' = prev dial in + let zero_count' = + if Dial.is_zero dial' then zero_count + 1 else zero_count + in + turn dial' zero_count' (Left (n - 1)) + | Right 0 -> + (dial, zero_count) + | Right n -> + let dial' = next dial in + let zero_count' = + if Dial.is_zero dial' then zero_count + 1 else zero_count + in + turn dial' zero_count' (Right (n - 1)) +end diff --git a/ocaml/lib/year2025/day02/part01/id.ml b/ocaml/lib/year2025/day02/part01/id.ml new file mode 100644 index 0000000..b7a3bd2 --- /dev/null +++ b/ocaml/lib/year2025/day02/part01/id.ml @@ -0,0 +1,16 @@ +module ID = struct + (** *) + type t = int + + let create num = num + + let validate rules id = List.fold_left (fun acc r -> acc && r id) true rules + + let incr = ( + ) 1 + + let to_int id = id + + let to_string = string_of_int + + let pp id = "ID=" ^ string_of_int id +end diff --git a/ocaml/lib/domain/d02p01.mli b/ocaml/lib/year2025/day02/part01/id.mli index 55665fe..63d5942 100644 --- a/ocaml/lib/domain/d02p01.mli +++ b/ocaml/lib/year2025/day02/part01/id.mli @@ -20,17 +20,3 @@ module ID : sig val pp : t -> string (** [pp id] is a pretty string representing [id] *) end - -module Range : sig - (** [t] is a range of values *) - type t - - val create : int * int -> t - (** [create (s, e)] is a range starting at [s] and ending at [e]. *) - - val collect : t -> ID.t list - (** [collect r] is a list containing all elements within the range (inclusive). *) - - val pp : t -> string - (** [pp r] is a pretty string representing [r] *) -end diff --git a/ocaml/lib/domain/d02p02.ml b/ocaml/lib/year2025/day02/part01/range.ml index b2b55f1..ba27568 100644 --- a/ocaml/lib/domain/d02p02.ml +++ b/ocaml/lib/year2025/day02/part01/range.ml @@ -1,15 +1,4 @@ -module ID = struct - (** *) - type t = int - - let create num = num - - let incr = ( + ) 1 - - let to_string = string_of_int - - let pp id = "ID=" ^ string_of_int id -end +open Id module Range = struct type t = ID.t * ID.t diff --git a/ocaml/lib/year2025/day02/part01/range.mli b/ocaml/lib/year2025/day02/part01/range.mli new file mode 100644 index 0000000..e525e43 --- /dev/null +++ b/ocaml/lib/year2025/day02/part01/range.mli @@ -0,0 +1,15 @@ +open Id + +module Range : sig + (** [t] is a range of values *) + type t + + val create : int * int -> t + (** [create (s, e)] is a range starting at [s] and ending at [e]. *) + + val collect : t -> ID.t list + (** [collect r] is a list containing all elements within the range (inclusive). *) + + val pp : t -> string + (** [pp r] is a pretty string representing [r] *) +end diff --git a/ocaml/lib/application/d02p01.ml b/ocaml/lib/year2025/day02/part01/solver.ml index f313149..417aa0d 100644 --- a/ocaml/lib/application/d02p01.ml +++ b/ocaml/lib/year2025/day02/part01/solver.ml @@ -1,4 +1,5 @@ -open Domain.D02p01 +open Id +open Range let err_empty_input = "input is empty" diff --git a/ocaml/lib/application/d02p01.mli b/ocaml/lib/year2025/day02/part01/solver.mli index 8a8eb32..8a8eb32 100644 --- a/ocaml/lib/application/d02p01.mli +++ b/ocaml/lib/year2025/day02/part01/solver.mli diff --git a/ocaml/lib/year2025/day02/part02/id.ml b/ocaml/lib/year2025/day02/part02/id.ml new file mode 100644 index 0000000..f26c395 --- /dev/null +++ b/ocaml/lib/year2025/day02/part02/id.ml @@ -0,0 +1,12 @@ +module ID = struct + (** *) + type t = int + + let create num = num + + let incr = ( + ) 1 + + let to_string = string_of_int + + let pp id = "ID=" ^ string_of_int id +end diff --git a/ocaml/lib/domain/d02p02.mli b/ocaml/lib/year2025/day02/part02/id.mli index f918ae1..a512593 100644 --- a/ocaml/lib/domain/d02p02.mli +++ b/ocaml/lib/year2025/day02/part02/id.mli @@ -14,17 +14,3 @@ module ID : sig val pp : t -> string (** [pp id] is a pretty string representing [id] *) end - -module Range : sig - (** [t] is a range of values *) - type t - - val create : int * int -> t - (** [create (s, e)] is a range starting at [s] and ending at [e]. *) - - val collect : t -> ID.t list - (** [collect r] is a list containing all elements within the range (inclusive). *) - - val pp : t -> string - (** [pp r] is a pretty string representing [r] *) -end diff --git a/ocaml/lib/domain/d02p01.ml b/ocaml/lib/year2025/day02/part02/range.ml index 725d4b1..ba27568 100644 --- a/ocaml/lib/domain/d02p01.ml +++ b/ocaml/lib/year2025/day02/part02/range.ml @@ -1,19 +1,4 @@ -module ID = struct - (** *) - type t = int - - let create num = num - - let validate rules id = List.fold_left (fun acc r -> acc && r id) true rules - - let incr = ( + ) 1 - - let to_int id = id - - let to_string = string_of_int - - let pp id = "ID=" ^ string_of_int id -end +open Id module Range = struct type t = ID.t * ID.t diff --git a/ocaml/lib/year2025/day02/part02/range.mli b/ocaml/lib/year2025/day02/part02/range.mli new file mode 100644 index 0000000..e525e43 --- /dev/null +++ b/ocaml/lib/year2025/day02/part02/range.mli @@ -0,0 +1,15 @@ +open Id + +module Range : sig + (** [t] is a range of values *) + type t + + val create : int * int -> t + (** [create (s, e)] is a range starting at [s] and ending at [e]. *) + + val collect : t -> ID.t list + (** [collect r] is a list containing all elements within the range (inclusive). *) + + val pp : t -> string + (** [pp r] is a pretty string representing [r] *) +end diff --git a/ocaml/lib/application/d02p02.ml b/ocaml/lib/year2025/day02/part02/solver.ml index d062f7b..f5fdf0c 100644 --- a/ocaml/lib/application/d02p02.ml +++ b/ocaml/lib/year2025/day02/part02/solver.ml @@ -1,4 +1,5 @@ -open Domain.D02p02 +open Id +open Range (* Errors *) diff --git a/ocaml/lib/application/d02p02.mli b/ocaml/lib/year2025/day02/part02/solver.mli index 8a8eb32..8a8eb32 100644 --- a/ocaml/lib/application/d02p02.mli +++ b/ocaml/lib/year2025/day02/part02/solver.mli diff --git a/ocaml/lib/year2025/day03/part01/battery.ml b/ocaml/lib/year2025/day03/part01/battery.ml new file mode 100644 index 0000000..cb2d9e5 --- /dev/null +++ b/ocaml/lib/year2025/day03/part01/battery.ml @@ -0,0 +1,13 @@ +module Battery = struct + type t = int + + let of_int i = i + + let to_int b = b + + let to_string = string_of_int + + let compare = Int.compare + + let pp = string_of_int +end diff --git a/ocaml/lib/year2025/day03/part01/battery.mli b/ocaml/lib/year2025/day03/part01/battery.mli new file mode 100644 index 0000000..e00940b --- /dev/null +++ b/ocaml/lib/year2025/day03/part01/battery.mli @@ -0,0 +1,13 @@ +module Battery : sig + type t + + val of_int : int -> t + + val to_int : t -> int + + val to_string : t -> string + + val compare : t -> t -> int + + val pp : t -> string +end diff --git a/ocaml/lib/domain/d03p01.ml b/ocaml/lib/year2025/day03/part01/battery_bank.ml index 1367712..7ebce75 100644 --- a/ocaml/lib/domain/d03p01.ml +++ b/ocaml/lib/year2025/day03/part01/battery_bank.ml @@ -1,45 +1,6 @@ -module Battery : sig - type t +open Battery - val of_int : int -> t - - val to_int : t -> int - - val to_string : t -> string - - val compare : t -> t -> int - - val pp : t -> string -end = struct - type t = int - - let of_int i = i - - let to_int b = b - - let to_string = string_of_int - - let compare = Int.compare - - let pp = string_of_int -end - -module BatteryBank : sig - type t - - val highest_joltage : t -> int - (** [highest_joltage bb] is an integer created from the two highest - digits in [bb]. - Raises: [Assert_failure] if [bb] is empty. *) - - val of_string : string -> t - - val of_list : Battery.t list -> t - - val to_list : t -> Battery.t list - - val pp : t -> string -end = struct +module BatteryBank = struct type t = Battery.t list let rec highest_joltage bb = diff --git a/ocaml/lib/year2025/day03/part01/battery_bank.mli b/ocaml/lib/year2025/day03/part01/battery_bank.mli new file mode 100644 index 0000000..bffc4cb --- /dev/null +++ b/ocaml/lib/year2025/day03/part01/battery_bank.mli @@ -0,0 +1,18 @@ +open Battery + +module BatteryBank : sig + type t + + val highest_joltage : t -> int + (** [highest_joltage bb] is an integer created from the two highest + digits in [bb]. + Raises: [Assert_failure] if [bb] is empty. *) + + val of_string : string -> t + + val of_list : Battery.t list -> t + + val to_list : t -> Battery.t list + + val pp : t -> string +end diff --git a/ocaml/lib/application/d03p01.ml b/ocaml/lib/year2025/day03/part01/solver.ml index 522f5d0..4a06e83 100644 --- a/ocaml/lib/application/d03p01.ml +++ b/ocaml/lib/year2025/day03/part01/solver.ml @@ -1,4 +1,4 @@ -open Domain.D03p01 +open Battery_bank let err_empty_input = "input is empty" diff --git a/ocaml/lib/application/d03p01.mli b/ocaml/lib/year2025/day03/part01/solver.mli index 31dd0cd..31dd0cd 100644 --- a/ocaml/lib/application/d03p01.mli +++ b/ocaml/lib/year2025/day03/part01/solver.mli diff --git a/ocaml/lib/year2025/day03/part02/battery.ml b/ocaml/lib/year2025/day03/part02/battery.ml new file mode 100644 index 0000000..e8f0443 --- /dev/null +++ b/ocaml/lib/year2025/day03/part02/battery.ml @@ -0,0 +1,25 @@ +module Battery : sig + type t + + val of_int : int -> t + + val to_int : t -> int + + val to_string : t -> string + + val compare : t -> t -> int + + val pp : t -> string +end = struct + type t = int + + let of_int i = i + + let to_int b = b + + let to_string = string_of_int + + let compare = Int.compare + + let pp = string_of_int +end diff --git a/ocaml/lib/year2025/day03/part02/battery.mli b/ocaml/lib/year2025/day03/part02/battery.mli new file mode 100644 index 0000000..e00940b --- /dev/null +++ b/ocaml/lib/year2025/day03/part02/battery.mli @@ -0,0 +1,13 @@ +module Battery : sig + type t + + val of_int : int -> t + + val to_int : t -> int + + val to_string : t -> string + + val compare : t -> t -> int + + val pp : t -> string +end diff --git a/ocaml/lib/domain/d03p02.ml b/ocaml/lib/year2025/day03/part02/battery_bank.ml index 88257d0..d7dc213 100644 --- a/ocaml/lib/domain/d03p02.ml +++ b/ocaml/lib/year2025/day03/part02/battery_bank.ml @@ -1,45 +1,6 @@ -module Battery : sig - type t +open Battery - val of_int : int -> t - - val to_int : t -> int - - val to_string : t -> string - - val compare : t -> t -> int - - val pp : t -> string -end = struct - type t = int - - let of_int i = i - - let to_int b = b - - let to_string = string_of_int - - let compare = Int.compare - - let pp = string_of_int -end - -module BatteryBank : sig - type t - - val highest_joltage : t -> int - (** [highest_joltage bb] is an integer created from the two highest - digits in [bb]. - Raises: [Assert_failure] if [bb] is empty. *) - - val of_string : string -> t - - val of_list : Battery.t list -> t - - val to_list : t -> Battery.t list - - val pp : t -> string -end = struct +module BatteryBank = struct type t = Battery.t list type highest = {one: Battery.t option; two: Battery.t option} diff --git a/ocaml/lib/year2025/day03/part02/battery_bank.mli b/ocaml/lib/year2025/day03/part02/battery_bank.mli new file mode 100644 index 0000000..bffc4cb --- /dev/null +++ b/ocaml/lib/year2025/day03/part02/battery_bank.mli @@ -0,0 +1,18 @@ +open Battery + +module BatteryBank : sig + type t + + val highest_joltage : t -> int + (** [highest_joltage bb] is an integer created from the two highest + digits in [bb]. + Raises: [Assert_failure] if [bb] is empty. *) + + val of_string : string -> t + + val of_list : Battery.t list -> t + + val to_list : t -> Battery.t list + + val pp : t -> string +end diff --git a/ocaml/lib/application/d03p02.ml b/ocaml/lib/year2025/day03/part02/solver.ml index 743c658..4a06e83 100644 --- a/ocaml/lib/application/d03p02.ml +++ b/ocaml/lib/year2025/day03/part02/solver.ml @@ -1,4 +1,4 @@ -open Domain.D03p02 +open Battery_bank let err_empty_input = "input is empty" diff --git a/ocaml/lib/application/d03p02.mli b/ocaml/lib/year2025/day03/part02/solver.mli index 93d3b98..93d3b98 100644 --- a/ocaml/lib/application/d03p02.mli +++ b/ocaml/lib/year2025/day03/part02/solver.mli diff --git a/ocaml/lib/application/d04p01.ml b/ocaml/lib/year2025/day04/part01/solver.ml index 7c69de4..7cc54f6 100644 --- a/ocaml/lib/application/d04p01.ml +++ b/ocaml/lib/year2025/day04/part01/solver.ml @@ -1,21 +1,21 @@ -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 matrix = Shared.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 neighbour_coords = + Shared.Matrix.M.get_valid_neighbours matrix x y + in let neighbours = List.map - (fun (x', y') -> Matrix.M.get matrix x' y') + (fun (x', y') -> Shared.Matrix.M.get matrix x' y') neighbour_coords in let paper_count = count_paper neighbours in diff --git a/ocaml/lib/application/d04p01.mli b/ocaml/lib/year2025/day04/part01/solver.mli index 873acff..873acff 100644 --- a/ocaml/lib/application/d04p01.mli +++ b/ocaml/lib/year2025/day04/part01/solver.mli diff --git a/ocaml/lib/application/d04p02.ml b/ocaml/lib/year2025/day04/part02/solver.ml index 75b1236..e92c982 100644 --- a/ocaml/lib/application/d04p02.ml +++ b/ocaml/lib/year2025/day04/part02/solver.ml @@ -1,5 +1,3 @@ -open Domain - let err_empty_input = "input is empty" let rec count_accessible_rolls matrix = @@ -21,9 +19,13 @@ and count_accessible_rolls_aux matrix count_paper accessible_rolls_of_paper = 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 neighbour_coords = + Shared.Matrix.M.get_valid_neighbours matrix x y + in let neighbours = - List.map (fun (nx, ny) -> Matrix.M.get matrix nx ny) neighbour_coords + List.map + (fun (nx, ny) -> Shared.Matrix.M.get matrix nx ny) + neighbour_coords in let paper_count = count_paper neighbours in let is_accessible = paper_count < 4 in @@ -34,7 +36,7 @@ and count_accessible_rolls_aux matrix count_paper accessible_rolls_of_paper = done done ; List.iter - (fun (x', y') -> Matrix.M.set matrix x' y' ".") + (fun (x', y') -> Shared.Matrix.M.set matrix x' y' ".") !accessible_rolls_of_paper and print_iteration_debug_msg x y neighbour_coords neighbours paper_count @@ -59,6 +61,6 @@ and print_iteration_debug_msg x y neighbour_coords neighbours paper_count let solve input () = if input = "" then Error err_empty_input else - let matrix = Matrix.M.of_string input in + let matrix = Shared.Matrix.M.of_string input in let accessible_rolls_of_paper = count_accessible_rolls matrix in Ok accessible_rolls_of_paper diff --git a/ocaml/lib/application/d04p02.mli b/ocaml/lib/year2025/day04/part02/solver.mli index 388ec56..388ec56 100644 --- a/ocaml/lib/application/d04p02.mli +++ b/ocaml/lib/year2025/day04/part02/solver.mli diff --git a/ocaml/lib/application/d06p01.ml b/ocaml/lib/year2025/day06/part01/solver.ml index 9425810..d992ac2 100644 --- a/ocaml/lib/application/d06p01.ml +++ b/ocaml/lib/year2025/day06/part01/solver.ml @@ -1,7 +1,7 @@ let err_empty_input = "input is empty" let log_matrix matrix = - let open Domain.Matrix in + let open Shared.Matrix in Logs.debug (fun m -> m "%s" (M.of_list matrix |> M.pp (fun elt -> elt))) let log_list lst = @@ -13,7 +13,7 @@ type operation = Mult | Add let solve input () = if input = "" then Error err_empty_input else - let input' = Parser.columns_of_string input in + let input' = Shared.Parser.columns_of_string input in assert (input' <> []) ; log_matrix input' ; let nums = diff --git a/ocaml/lib/application/d06p01.mli b/ocaml/lib/year2025/day06/part01/solver.mli index b3abc1e..b3abc1e 100644 --- a/ocaml/lib/application/d06p01.mli +++ b/ocaml/lib/year2025/day06/part01/solver.mli diff --git a/ocaml/lib/application/d06p02.ml b/ocaml/lib/year2025/day06/part02/solver.ml index 9425810..d992ac2 100644 --- a/ocaml/lib/application/d06p02.ml +++ b/ocaml/lib/year2025/day06/part02/solver.ml @@ -1,7 +1,7 @@ let err_empty_input = "input is empty" let log_matrix matrix = - let open Domain.Matrix in + let open Shared.Matrix in Logs.debug (fun m -> m "%s" (M.of_list matrix |> M.pp (fun elt -> elt))) let log_list lst = @@ -13,7 +13,7 @@ type operation = Mult | Add let solve input () = if input = "" then Error err_empty_input else - let input' = Parser.columns_of_string input in + let input' = Shared.Parser.columns_of_string input in assert (input' <> []) ; log_matrix input' ; let nums = diff --git a/ocaml/lib/application/d06p02.mli b/ocaml/lib/year2025/day06/part02/solver.mli index 49444de..49444de 100644 --- a/ocaml/lib/application/d06p02.mli +++ b/ocaml/lib/year2025/day06/part02/solver.mli diff --git a/ocaml/lib/application/dune b/ocaml/lib/year2025/dune index b78613a..99d5c0a 100644 --- a/ocaml/lib/application/dune +++ b/ocaml/lib/year2025/dune @@ -1,7 +1,9 @@ +(include_subdirs qualified) + (library - (name application) + (name year2025) (libraries - domain + shared fmt logs) (inline_tests) @@ -10,5 +12,5 @@ ppx_deriving.show ppx_deriving.eq ppx_deriving.ord - ppx_inline_test - ppx_expect))) + ppx_expect + ppx_inline_test))) diff --git a/ocaml/test/application/dune b/ocaml/test/application/dune deleted file mode 100644 index 7a90f81..0000000 --- a/ocaml/test/application/dune +++ /dev/null @@ -1,9 +0,0 @@ -(tests - (names - test_d01p01 - test_d01p02 - test_d04p01) - (libraries - application - domain - alcotest)) diff --git a/ocaml/test/infrastructure/dune b/ocaml/test/infrastructure/dune deleted file mode 100644 index 5d493d9..0000000 --- a/ocaml/test/infrastructure/dune +++ /dev/null @@ -1,8 +0,0 @@ -(tests - (names - test_example) - (libraries - application - domain - infrastructure - alcotest)) diff --git a/ocaml/test/infrastructure/test_example.ml b/ocaml/test/infrastructure/test_example.ml deleted file mode 100644 index e69de29..0000000 --- a/ocaml/test/infrastructure/test_example.ml +++ /dev/null diff --git a/ocaml/test/presentation/dune b/ocaml/test/presentation/dune deleted file mode 100644 index e34e56f..0000000 --- a/ocaml/test/presentation/dune +++ /dev/null @@ -1,11 +0,0 @@ -(tests - (names - test_example) - (libraries - application - domain - infrastructure - presentation - alcotest - qcheck-core - qcheck-alcotest)) diff --git a/ocaml/test/presentation/test_example.ml b/ocaml/test/presentation/test_example.ml deleted file mode 100644 index e69de29..0000000 --- a/ocaml/test/presentation/test_example.ml +++ /dev/null diff --git a/ocaml/test/year2025/day01/part01/dune b/ocaml/test/year2025/day01/part01/dune new file mode 100644 index 0000000..52cff9d --- /dev/null +++ b/ocaml/test/year2025/day01/part01/dune @@ -0,0 +1,11 @@ +(tests + (names + test_dial + test_solver) + (libraries + year2025 + alcotest + qcheck-core + qcheck-alcotest) + (action (run %{test} -e)) + (modes byte exe)) diff --git a/ocaml/test/domain/test_d01p01.ml b/ocaml/test/year2025/day01/part01/test_dial.ml index 23404f6..2175bee 100644 --- a/ocaml/test/domain/test_d01p01.ml +++ b/ocaml/test/year2025/day01/part01/test_dial.ml @@ -1,4 +1,4 @@ -open Domain.D01p01 +open Year2025.Day01.Part01.Dial let test_start () = Alcotest.(check int) "incorrect starting state" 50 (Dial.to_int Dial.start) diff --git a/ocaml/test/application/test_d01p01.ml b/ocaml/test/year2025/day01/part01/test_solver.ml index e57db01..e420ee2 100644 --- a/ocaml/test/application/test_d01p01.ml +++ b/ocaml/test/year2025/day01/part01/test_solver.ml @@ -1,4 +1,4 @@ -open Application.D01p01 +open Year2025.Day01.Part01.Solver let example_data = {|L68 L30 diff --git a/ocaml/test/year2025/day01/part02/dune b/ocaml/test/year2025/day01/part02/dune new file mode 100644 index 0000000..52cff9d --- /dev/null +++ b/ocaml/test/year2025/day01/part02/dune @@ -0,0 +1,11 @@ +(tests + (names + test_dial + test_solver) + (libraries + year2025 + alcotest + qcheck-core + qcheck-alcotest) + (action (run %{test} -e)) + (modes byte exe)) diff --git a/ocaml/test/domain/test_d01p02.ml b/ocaml/test/year2025/day01/part02/test_dial.ml index 98c06c3..2d09635 100644 --- a/ocaml/test/domain/test_d01p02.ml +++ b/ocaml/test/year2025/day01/part02/test_dial.ml @@ -1,4 +1,5 @@ -open Domain.D01p02 +open Year2025.Day01.Part02.Dial +open Year2025.Day01.Part02.Turner let test_start () = Alcotest.(check int) "incorrect starting state" 50 (Dial.to_int Dial.start) diff --git a/ocaml/test/application/test_d01p02.ml b/ocaml/test/year2025/day01/part02/test_solver.ml index bbda035..c4c1123 100644 --- a/ocaml/test/application/test_d01p02.ml +++ b/ocaml/test/year2025/day01/part02/test_solver.ml @@ -1,4 +1,4 @@ -open Application.D01p02 +open Year2025.Day01.Part02.Solver let example_data = {|L68 L30 diff --git a/ocaml/test/year2025/day03/part01/dune b/ocaml/test/year2025/day03/part01/dune new file mode 100644 index 0000000..af1f340 --- /dev/null +++ b/ocaml/test/year2025/day03/part01/dune @@ -0,0 +1,10 @@ +(tests + (names + test_battery_bank) + (libraries + year2025 + alcotest + qcheck-core + qcheck-alcotest) + (action (run %{test} -e)) + (modes byte exe)) diff --git a/ocaml/test/domain/test_d03p01.ml b/ocaml/test/year2025/day03/part01/test_battery_bank.ml index 6a2b3cf..6bfaa53 100644 --- a/ocaml/test/domain/test_d03p01.ml +++ b/ocaml/test/year2025/day03/part01/test_battery_bank.ml @@ -1,4 +1,4 @@ -open Domain.D03p01 +open Year2025.Day03.Part01.Battery_bank let test_highest_joltage have want () = Alcotest.(check int) diff --git a/ocaml/test/domain/dune b/ocaml/test/year2025/day04/part01/dune index 1364288..aeee9b4 100644 --- a/ocaml/test/domain/dune +++ b/ocaml/test/year2025/day04/part01/dune @@ -1,11 +1,10 @@ (tests (names - test_d01p01 - test_d01p02 - test_d03p01) + test_solver) (libraries - domain + year2025 alcotest qcheck-core qcheck-alcotest) + (action (run %{test} -e)) (modes byte exe)) diff --git a/ocaml/test/application/test_d04p01.ml b/ocaml/test/year2025/day04/part01/test_solver.ml index ffbe102..77e33a5 100644 --- a/ocaml/test/application/test_d04p01.ml +++ b/ocaml/test/year2025/day04/part01/test_solver.ml @@ -1,4 +1,4 @@ -open Application.D04p01 +open Year2025.Day04.Part01.Solver let example = {|..@@.@@@@. |
