-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathday04.ml
More file actions
28 lines (22 loc) · 713 Bytes
/
day04.ml
File metadata and controls
28 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Strset = Set.Make(String)
let input =
CCIO.(with_in "inputs/04.txt" read_lines_l)
|> List.map (String.split_on_char ' ')
let count_valid lines =
let only_distinct_words line =
let original_length = List.length line in
let distinct_length = line |> Strset.of_list |> Strset.cardinal in
original_length = distinct_length
in
lines |> List.filter only_distinct_words |> List.length
let anagrams lines =
let sort_chars line =
line
|> CCString.to_list
|> List.sort Char.compare
|> CCString.of_list
in
List.map (List.map sort_chars) lines
let solve = CCFun.(count_valid %> Printf.printf "%d\n")
let part_1 = input |> solve
let part_2 = input |> anagrams |> solve