factor out mains
This commit is contained in:
parent
d20143a6d2
commit
c6ba203526
1 changed files with 8 additions and 10 deletions
18
day4.ml
18
day4.ml
|
@ -79,13 +79,15 @@ let%test_module _ = (module struct
|
|||
end)
|
||||
|
||||
|
||||
|
||||
let main1 file =
|
||||
let sets = chunk_input file |> List.map field_keys in
|
||||
let len_all = List.length sets in
|
||||
let len_valid = List.(length (filter valid_set sets)) in
|
||||
let main' make valid file =
|
||||
let items = chunk_input file |> List.map make in
|
||||
let len_all = List.length items in
|
||||
let len_valid = List.(length (filter valid items)) in
|
||||
Printf.printf "%d valid out of %d\n" len_valid len_all
|
||||
|
||||
|
||||
let main1 = main' field_keys valid_set
|
||||
|
||||
let%expect_test "part 1" =
|
||||
main1 "../../data/day4";
|
||||
[%expect{| 233 valid out of 288 |}]
|
||||
|
@ -223,11 +225,7 @@ let%test_module _ = (module struct
|
|||
end)
|
||||
|
||||
|
||||
let main2 file =
|
||||
let maps = chunk_input file |> List.map fields in
|
||||
let len_all = List.length maps in
|
||||
let len_valid = List.(length (filter valid_map maps)) in
|
||||
Printf.printf "%d valid out of %d\n" len_valid len_all
|
||||
let main2 = main' fields valid_map
|
||||
|
||||
let%expect_test _ =
|
||||
main2 "../../data/day4";
|
||||
|
|
Loading…
Reference in a new issue