From dbdeb7eaf3b92308e4895eb76dd9f3c5dae5b041 Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Tue, 19 Aug 2025 00:48:54 +0200 Subject: some change idk --- 2023/Go/go.mod | 8 ++++++++ 2023/Go/go.sum | 8 ++++++++ 2023/Go/internal/day_01/day_01.go | 6 ++---- 2023/Go/main.go | 1 + 2024/OCaml/AoC_2024.opam | 2 +- 2024/OCaml/lib/day_04/part_01.ml | 5 +++-- 2024/OCaml/lib/grid/cell.ml | 18 ++++++++++++++++++ 2024/OCaml/lib/grid/cell.mli | 18 ++++++++++++++++++ 2024/OCaml/lib/grid/grid.ml | 14 ++++++++++++++ 2024/OCaml/lib/grid/grid.mli | 6 ++++++ 2024/OCaml/test/day_04_part_01.ml | 30 ++++++++++++++++++++---------- 2024/OCaml/test/dune | 3 ++- 2024/OCaml/test/grid.ml | 5 +++++ 13 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 2023/Go/go.sum create mode 100644 2024/OCaml/lib/grid/cell.ml create mode 100644 2024/OCaml/lib/grid/cell.mli create mode 100644 2024/OCaml/lib/grid/grid.ml create mode 100644 2024/OCaml/lib/grid/grid.mli create mode 100644 2024/OCaml/test/grid.ml diff --git a/2023/Go/go.mod b/2023/Go/go.mod index 1c60379..9fba23c 100644 --- a/2023/Go/go.mod +++ b/2023/Go/go.mod @@ -1,3 +1,11 @@ module github.com/DJOLEARY/Advent_of_Code/2023/Go go 1.22.3 + +require github.com/outrigdev/outrig v0.8.2 + +require ( + github.com/google/uuid v1.6.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/term v0.29.0 // indirect +) diff --git a/2023/Go/go.sum b/2023/Go/go.sum new file mode 100644 index 0000000..3c60b26 --- /dev/null +++ b/2023/Go/go.sum @@ -0,0 +1,8 @@ +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/outrigdev/outrig v0.8.2 h1:+qR+N6BXvJmFXsHmksaAJk4sgItxHLbWXN+9K8W2UVM= +github.com/outrigdev/outrig v0.8.2/go.mod h1:8ULH17Fc55s9zkf6S2ndQ43UoiJ0j28t9A0lwjs7rQc= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= +golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= diff --git a/2023/Go/internal/day_01/day_01.go b/2023/Go/internal/day_01/day_01.go index c646a4d..9cd0a49 100644 --- a/2023/Go/internal/day_01/day_01.go +++ b/2023/Go/internal/day_01/day_01.go @@ -2,6 +2,7 @@ package day_01 import ( "errors" + "fmt" "os" "strconv" "strings" @@ -16,7 +17,6 @@ func Solve() { lines := strings.Split(content, "\n") for _, line := range lines { first_num, last_num, err := findNumbers(line) - if err != nil { continue } @@ -28,12 +28,11 @@ func Solve() { acc := accumulate(numbers) - println(acc) + fmt.Println(acc) } func readFile(filename string) string { content, err := os.ReadFile(filename) - if err != nil { panic(err) } @@ -107,7 +106,6 @@ func accumulate(numbers []int) int { func strToInt(str string) int { num, err := strconv.ParseInt(str, 0, 0) - if err != nil { panic(err) } diff --git a/2023/Go/main.go b/2023/Go/main.go index c8f7100..7d71b47 100644 --- a/2023/Go/main.go +++ b/2023/Go/main.go @@ -13,6 +13,7 @@ import ( day_06_part_01 "github.com/DJOLEARY/Advent_of_Code/2023/Go/internal/day_06/part_01" day_06_part_02 "github.com/DJOLEARY/Advent_of_Code/2023/Go/internal/day_06/part_02" day_07_part_01 "github.com/DJOLEARY/Advent_of_Code/2023/Go/internal/day_07/part_01" + _ "github.com/outrigdev/outrig/autoinit" ) func main() { diff --git a/2024/OCaml/AoC_2024.opam b/2024/OCaml/AoC_2024.opam index 4676487..6be14e1 100644 --- a/2024/OCaml/AoC_2024.opam +++ b/2024/OCaml/AoC_2024.opam @@ -4,7 +4,7 @@ synopsis: "Advent of Code 2024" description: "Solutions to the Advent of Code puzzles for 2024" maintainer: ["D.J. O'Leary"] authors: ["D.J. O'Leary"] -license: "MIT" +license: "Unlicense" tags: ["aoc2024" "Advent of Code 2024"] homepage: "https://github.com/DJOLEARY/Advent_of_Code" doc: diff --git a/2024/OCaml/lib/day_04/part_01.ml b/2024/OCaml/lib/day_04/part_01.ml index 63c1cfd..acb3e3b 100644 --- a/2024/OCaml/lib/day_04/part_01.ml +++ b/2024/OCaml/lib/day_04/part_01.ml @@ -6,8 +6,9 @@ type direction = N | NE | E | SE | S | SW | W | NW let all_directions = [ N; NE; E; SE; S; SW; W; NW ] let needle = "XMAS" -(** [calculate_row_offset lines] is the offset used to move between the rows of the concatenated variant of [lines] as though it were a grid. - Requires: values of [lines] all have the same length *) +(** [calculate_row_offset lines] is the offset used to move between the rows of + the concatenated variant of [lines] as though it were a grid. Requires: + values of [lines] all have the same length *) let calculate_row_offset lines = match lines with [] -> 0 | h :: _ -> String.length h diff --git a/2024/OCaml/lib/grid/cell.ml b/2024/OCaml/lib/grid/cell.ml new file mode 100644 index 0000000..186e451 --- /dev/null +++ b/2024/OCaml/lib/grid/cell.ml @@ -0,0 +1,18 @@ +type t = { + value : string; + up : t option; + down : t option; + left : t option; + right : t option; +} + +let create value = { value; up = None; down = None; left = None; right = None } +let with_up up c = { c with up = Some up } +let with_down down c = { c with down = Some down } +let with_left left c = { c with left = Some left } +let with_right right c = { c with right = Some right } +let move_up co = match co with Some c -> c.up | None -> None +let move_down co = match co with Some c -> c.down | None -> None +let move_left co = match co with Some c -> c.left | None -> None +let move_right co = match co with Some c -> c.right | None -> None +let ( = ) c1 c2 = c1.value = c2.value diff --git a/2024/OCaml/lib/grid/cell.mli b/2024/OCaml/lib/grid/cell.mli new file mode 100644 index 0000000..e61e34a --- /dev/null +++ b/2024/OCaml/lib/grid/cell.mli @@ -0,0 +1,18 @@ +type t = { + value : string; + up : t option; + down : t option; + left : t option; + right : t option; +} + +val create : string -> t +val with_up : t -> t -> t +val with_down : t -> t -> t +val with_left : t -> t -> t +val with_right : t -> t -> t +val move_up : t option -> t option +val move_down : t option -> t option +val move_left : t option -> t option +val move_right : t option -> t option +val ( = ) : t -> t -> bool diff --git a/2024/OCaml/lib/grid/grid.ml b/2024/OCaml/lib/grid/grid.ml new file mode 100644 index 0000000..0d6bc4c --- /dev/null +++ b/2024/OCaml/lib/grid/grid.ml @@ -0,0 +1,14 @@ +let rec to_grid_aux tokens max_width acc = + match tokens with + | [] -> acc + | h :: t -> + let new_cell = Cell.create h |> Cell.with_left acc in + let new_acc = acc |> Cell.with_right new_cell in + to_grid_aux t max_width new_acc + +let to_grid tokens max_width : Cell.t option = + match tokens with + | [] -> None + | h :: t -> + let first_cell = Cell.create h in + Some (to_grid_aux t max_width first_cell) diff --git a/2024/OCaml/lib/grid/grid.mli b/2024/OCaml/lib/grid/grid.mli new file mode 100644 index 0000000..31c4329 --- /dev/null +++ b/2024/OCaml/lib/grid/grid.mli @@ -0,0 +1,6 @@ +val to_grid : string list -> int -> Cell.t option +(** The cell in the top left corner of the grid is returned where each element + of [tokens] is converted into rows with [width]. An empty list of [tokens] + returns None. Requires: [width] is greater than 0 **) + +val print : Cell.t -> () diff --git a/2024/OCaml/test/day_04_part_01.ml b/2024/OCaml/test/day_04_part_01.ml index 9f43df0..9550e5b 100644 --- a/2024/OCaml/test/day_04_part_01.ml +++ b/2024/OCaml/test/day_04_part_01.ml @@ -36,7 +36,8 @@ let calculate_num_of_matches_tests = "is 0 when no matches present" >:: test_calculate_num_of_matches 0 "SMMX" 1 { index = 3; character = 'X' }; "is 1 when only one match present - top to bottom" - >:: (* + >:: + (* |.|X|.| |.|M|.| |.|A|.| @@ -45,7 +46,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 ".X..M..A..S." 3 { index = 1; character = 'X' }; "is 1 when only one match present - top to bottom edge" - >:: (* + >:: + (* |X|.|.| |M|.|.| |A|.|.| @@ -54,7 +56,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 "X..M..A..S.." 3 { index = 0; character = 'X' }; "is 1 when only one match present - bottom to top" - >:: (* + >:: + (* |.|S|.| |.|A|.| |.|M|.| @@ -63,17 +66,20 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 ".S..A..M..X." 3 { index = 10; character = 'X' }; "is 1 when only one match present - left to right" - >:: (* + >:: + (* |X|M|A|S| *) test_calculate_num_of_matches 1 "XMAS" 4 { index = 0; character = 'X' }; "is 1 when only one match present - right to left" - >:: (* + >:: + (* |S|A|M|X| *) test_calculate_num_of_matches 1 "SAMX" 4 { index = 3; character = 'X' }; "is 1 when only one match present - bottom right to top left" - >:: (* + >:: + (* |S|.|.|.| |.|A|.|.| |.|.|M|.| @@ -82,7 +88,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 "S....A....M....X" 4 { index = 15; character = 'X' }; "is 1 when only one match present - top left to bottom right" - >:: (* + >:: + (* |X|.|.|.| |.|M|.|.| |.|.|A|.| @@ -91,7 +98,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 "X....M....A....S" 4 { index = 0; character = 'X' }; "is 1 when only one match present - bottom left to top right" - >:: (* + >:: + (* |.|.|.|S| |.|.|A|.| |.|M|.|.| @@ -100,7 +108,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 "...S..A..M..X..." 4 { index = 12; character = 'X' }; "is 1 when only one match present - top right to bottom left" - >:: (* + >:: + (* |.|.|.|X| |.|.|M|.| |.|A|.|.| @@ -109,7 +118,8 @@ let calculate_num_of_matches_tests = test_calculate_num_of_matches 1 "...X..M..A..S..." 4 { index = 3; character = 'X' }; "is 8 when matches present in all possible directions" - >:: (* + >:: + (* |S|.|.|S|.|.|S| |.|A|.|A|.|A|.| |.|.|M|M|M|.|.| diff --git a/2024/OCaml/test/dune b/2024/OCaml/test/dune index 8d01938..d4a5b26 100644 --- a/2024/OCaml/test/dune +++ b/2024/OCaml/test/dune @@ -3,6 +3,7 @@ day_01_part_02 day_02_part_01 day_03_part_01 - day_04_part_01) + day_04_part_01 + grid) (modes byte exe) (libraries AoC_2024 ounit2)) diff --git a/2024/OCaml/test/grid.ml b/2024/OCaml/test/grid.ml new file mode 100644 index 0000000..bd384cd --- /dev/null +++ b/2024/OCaml/test/grid.ml @@ -0,0 +1,5 @@ +open OUnit2 +open AoC_2024.Grid + +let tests = "" >::: [] +let _ = run_test_tt_main tests -- cgit v1.2.3