Skip to content

Commit 74f371f

Browse files
committed
2025 Day 6
1 parent d19cfd7 commit 74f371f

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

2025/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
_build
2+
inputs

2025/bin/main.ml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open Aoc2025
22

3-
let () =
4-
let aoc = Aoc.new_ctx () in
5-
Aoc.run_days aoc
3+
let main () =
4+
let aoc = Aoc.new_ctx () in
5+
Aoc.run_days aoc
6+
7+
let () = main ()

2025/days/Day06.ml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
open Utils
22

3+
let parse input =
4+
let (ops, numbers) = String.split_on_char '\n' input
5+
|> List.rev
6+
|> function
7+
| [] -> failwith "bad input"
8+
| x::xs -> x ^ " ", List.rev xs |> List.map (fun s -> s ^ " ")
9+
in
10+
let (s1, s2, _, _, _) = fold_range (fun (s1, s2, op, vers, hors) i ->
11+
let op = match op with
12+
| Some op -> Some op
13+
| None -> (match ops.[i] with
14+
| '*' -> Some (List.fold_left ( * ) 1)
15+
| '+' -> Some (List.fold_left (+) 0)
16+
| _ -> None) in
17+
let n_vers = List.fold_left (fun a -> function
18+
| '0'..'9' as c -> a * 10 + (int_of_char c - int_of_char '0')
19+
| _ -> a) 0 (List.map (fun l -> l.[i]) numbers) in
20+
let hors = List.map2 (fun a l -> match l.[i] with
21+
| '0'..'9' as c -> a * 10 + (int_of_char c - int_of_char '0')
22+
| _ -> a) hors numbers in
23+
if List.for_all (fun l -> l.[i] = ' ') numbers then
24+
let op = Option.get op in
25+
(s1 + op hors, s2 + op vers, None, [], List.map (fun _ -> 0) numbers)
26+
else
27+
(s1, s2, op, n_vers :: vers, hors)
28+
29+
) (0, 0, None, [], List.map (fun _ -> 0) numbers) 0 (String.length ops - 1)
30+
in
31+
s1, s2
32+
333
let day06 input =
4-
("TODO", "TODO")
34+
let input = trim_end_nl input in
35+
let part1, part2 = parse input in
36+
(string_of_int part1, string_of_int part2)
537

638

2025/days/Utils.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@ let string_split_once pat s =
7070
let patlen, len = String.length pat, String.length s in
7171
let i = string_find_index pat s in
7272
(String.sub s 0 i, String.sub s (i + patlen) (len - i - patlen))
73+
74+
let (<%) f g x = f (g x)
75+
let (%>) f g x = g (f x)
76+
77+
let cons a l = a :: l
78+
79+
let transpose = function
80+
| [] -> []
81+
| x::xs -> List.(fold_right (fun l a -> map2 cons l a) (x::xs) (map (fun _ -> []) x) )

2025/lib/Aoc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let days =
4949
(3, Day03.day03);
5050
(4, Day04.day04);
5151
(5, Day05.day05);
52-
(* (6, Day06.day06); *)
52+
(6, Day06.day06);
5353
(* (7, Day07.day07); *)
5454
(* (8, Day08.day08); *)
5555
(* (9, Day09.day09); *)

0 commit comments

Comments
 (0)