Skip to content

Commit e49f3c6

Browse files
committed
Output parts 1 and 2 for day 1
1 parent 80db8b0 commit e49f3c6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

2023/one/one.ml

+19-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ let rec grab acc n lst =
2020
| _, h :: t -> grab (acc ^ h) (n - 1) t
2121
| _ -> ""
2222

23-
let get_num lst = match lst with
23+
let get_num p2 lst = match lst with
2424
| h :: _ when Str.string_match (Str.regexp "[0-9]") h 0 -> Some (int_of_string h)
2525
| _ ->
26+
if not p2 then None else
2627
let three, four, five = grab "" 3 lst, grab "" 4 lst, grab "" 5 lst in
2728
let f x = List.assoc_opt x digits in
2829
begin
@@ -34,7 +35,7 @@ let get_num lst = match lst with
3435
| _ -> failwith "bad input"
3536
end
3637

37-
let rec calibration str fst lst =
38+
let rec calibration p2 str fst lst =
3839
match str with
3940
| [] ->
4041
begin
@@ -45,21 +46,30 @@ let rec calibration str fst lst =
4546
end
4647
| _ :: t ->
4748
begin
48-
match get_num str with
49+
match get_num p2 str with
4950
| Some x ->
5051
let fst, lst =
5152
begin
5253
match fst with
5354
| Some _ -> fst, Some x
5455
| None -> Some x, lst
5556
end
56-
in calibration t fst lst
57-
| None -> calibration t fst lst
57+
in calibration p2 t fst lst
58+
| None -> calibration p2 t fst lst
5859
end
5960

61+
let yeet part = List.fold_left (fun acc x -> calibration part x None None + acc) 0
62+
63+
let _ =
64+
In_channel.input_lines (open_in "one.txt")
65+
|> List.map explode
66+
|> yeet false
67+
|> string_of_int
68+
|> print_endline
69+
6070
let _ =
6171
In_channel.input_lines (open_in "one.txt")
62-
|> List.map explode
63-
|> List.fold_left (fun acc x -> calibration x None None + acc) 0
64-
|> string_of_int
65-
|> print_endline
72+
|> List.map explode
73+
|> yeet true
74+
|> string_of_int
75+
|> print_endline

0 commit comments

Comments
 (0)