Compare commits

..

3 Commits

Author SHA1 Message Date
fbe531a10c Add README. 2024-12-03 16:37:47 +00:00
c8b0f5d61c Update package descriptions 2024-12-03 16:32:26 +00:00
4c41fd05f5 Comments and function renames. 2024-12-03 16:32:14 +00:00
4 changed files with 38 additions and 12 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
_build/ _build/
_opam/ _opam/
aoc.opam
input*.txt input*.txt

19
README.md Normal file
View File

@@ -0,0 +1,19 @@
# Advent of Code Implementations
Solutions to Advent of code problems written in OCaml
Copyright 2024, Matthew Gretton-Dann.
Licensed under the [Apache 2.0 license](./LICENSE).
## Build instructions
1. Install `ocaml`
2. Clone repository: `git clone https://gitea.gretton-dann.synology.me/mgrettondann/ocaml-aoc.git`
3. Enter directory: `cd ocaml-acc`
4. Set up switch: `opam switch create .`
5. Build with dune: `dune build`
## Executing tests
Tests are named as `bin/dayYYNN.exe`, where `YY` is the last two digits of the year, and `NN` is the day. For example `bin/day2401.exe` is the executable for 2024 day 1. All tests take a command line option containing the file name of puzzle input.

View File

@@ -1,7 +1,11 @@
type cmd = Do | Donot | Mul of int * int (** Type containing commands available in input *)
type cmd =
| Do (** Enable processing *)
| Donot (** Disable processing *)
| Mul of int * int (** Multiply two integers. *)
(** [find_nums s] returns the list of instructions given in [s]. *) (** [find_nums s] returns the list of instructions given in [s]. *)
let instrs_of_string s = let cmds_of_string s =
let r = let r =
Str.regexp Str.regexp
{|do()\|don't()\|mul(\([0-9][0-9]?[0-9]?\),\([0-9][0-9]?[0-9]?\))|} {|do()\|don't()\|mul(\([0-9][0-9]?[0-9]?\),\([0-9][0-9]?[0-9]?\))|}
@@ -23,8 +27,8 @@ let instrs_of_string s =
in in
List.rev (impl [] 0) List.rev (impl [] 0)
let instrs_of_file fname = let cmds_of_file fname =
Aoc.strings_of_file fname |> List.map instrs_of_string |> List.concat Aoc.strings_of_file fname |> List.map cmds_of_string |> List.concat
(** [mac acc a b] returns [acc + a * b]. *) (** [mac acc a b] returns [acc + a * b]. *)
let mac acc = function Mul (a, b) -> acc + (a * b) | _ -> acc let mac acc = function Mul (a, b) -> acc + (a * b) | _ -> acc
@@ -42,5 +46,4 @@ let day2403b lst =
impl 0 true lst impl 0 true lst
let _ = let _ =
Aoc.main instrs_of_file Aoc.main cmds_of_file [ (string_of_int, day2403a); (string_of_int, day2403b) ]
[ (string_of_int, day2403a); (string_of_int, day2403b) ]

View File

@@ -2,16 +2,18 @@
(name aoc) (name aoc)
(generate_opam_files)
(source (source
(github matt-gretton-dann/ocaml-aoc)) (uri https://gitea.gretton-dann.synology.me/mgrettondann/ocaml-aoc.git))
(authors "Matthew Gretton-Dann") (authors "Matthew Gretton-Dann <matt+ocaml-aoc@gretton-dann.org.uk>")
(maintainers "Matthew Gretton-Dann") (maintainers "Matthew Gretton-Dann <matt+ocaml-aoc@gretton-dann.org.uk>")
(license LICENSE) (license Apache-2.0)
(documentation https://url/to/documentation) (documentation https://gitea.gretton-dann.synology.me/mgrettondann/ocaml-aoc)
(package (package
(name aoc) (name aoc)
@@ -20,6 +22,6 @@
"Implementation of solutions to various Advent of Code exercises written in OCaml") "Implementation of solutions to various Advent of Code exercises written in OCaml")
(depends ocaml dune) (depends ocaml dune)
(tags (tags
(topics "to describe" your project))) (advent-of-code ocaml)))
; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html ; See the complete stanza docs at https://dune.readthedocs.io/en/stable/reference/dune-project/index.html