@@ -20,9 +20,10 @@ let rec grab acc n lst =
20
20
| _ , h :: t -> grab (acc ^ h) (n - 1 ) t
21
21
| _ -> " "
22
22
23
- let get_num lst = match lst with
23
+ let get_num p2 lst = match lst with
24
24
| h :: _ when Str. string_match (Str. regexp " [0-9]" ) h 0 -> Some (int_of_string h)
25
25
| _ ->
26
+ if not p2 then None else
26
27
let three, four, five = grab " " 3 lst, grab " " 4 lst, grab " " 5 lst in
27
28
let f x = List. assoc_opt x digits in
28
29
begin
@@ -34,7 +35,7 @@ let get_num lst = match lst with
34
35
| _ -> failwith " bad input"
35
36
end
36
37
37
- let rec calibration str fst lst =
38
+ let rec calibration p2 str fst lst =
38
39
match str with
39
40
| [] ->
40
41
begin
@@ -45,21 +46,30 @@ let rec calibration str fst lst =
45
46
end
46
47
| _ :: t ->
47
48
begin
48
- match get_num str with
49
+ match get_num p2 str with
49
50
| Some x ->
50
51
let fst, lst =
51
52
begin
52
53
match fst with
53
54
| Some _ -> fst, Some x
54
55
| None -> Some x, lst
55
56
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
58
59
end
59
60
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
+
60
70
let _ =
61
71
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