Compare commits
3 Commits
1f99f23c92
...
fbe531a10c
Author | SHA1 | Date | |
---|---|---|---|
fbe531a10c
|
|||
c8b0f5d61c
|
|||
4c41fd05f5
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
_build/
|
||||
_opam/
|
||||
aoc.opam
|
||||
|
||||
input*.txt
|
||||
|
19
README.md
Normal file
19
README.md
Normal 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.
|
@@ -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]. *)
|
||||
let instrs_of_string s =
|
||||
let cmds_of_string s =
|
||||
let r =
|
||||
Str.regexp
|
||||
{|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
|
||||
List.rev (impl [] 0)
|
||||
|
||||
let instrs_of_file fname =
|
||||
Aoc.strings_of_file fname |> List.map instrs_of_string |> List.concat
|
||||
let cmds_of_file fname =
|
||||
Aoc.strings_of_file fname |> List.map cmds_of_string |> List.concat
|
||||
|
||||
(** [mac acc a b] returns [acc + a * b]. *)
|
||||
let mac acc = function Mul (a, b) -> acc + (a * b) | _ -> acc
|
||||
@@ -42,5 +46,4 @@ let day2403b lst =
|
||||
impl 0 true lst
|
||||
|
||||
let _ =
|
||||
Aoc.main instrs_of_file
|
||||
[ (string_of_int, day2403a); (string_of_int, day2403b) ]
|
||||
Aoc.main cmds_of_file [ (string_of_int, day2403a); (string_of_int, day2403b) ]
|
||||
|
14
dune-project
14
dune-project
@@ -2,16 +2,18 @@
|
||||
|
||||
(name aoc)
|
||||
|
||||
(generate_opam_files)
|
||||
|
||||
(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
|
||||
(name aoc)
|
||||
@@ -20,6 +22,6 @@
|
||||
"Implementation of solutions to various Advent of Code exercises written in OCaml")
|
||||
(depends ocaml dune)
|
||||
(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
|
||||
|
Reference in New Issue
Block a user