38 lines
986 B
OCaml
38 lines
986 B
OCaml
(*
|
|
|
|
--- Day 4: High-Entropy Passphrases ---
|
|
|
|
A new system policy has been put in place that requires all accounts to use a passphrase instead of simply a password. A passphrase consists of a series of words (lowercase letters) separated by spaces.
|
|
|
|
To ensure security, a valid passphrase must contain no duplicate words.
|
|
|
|
For example:
|
|
|
|
aa bb cc dd ee is valid.
|
|
aa bb cc dd aa is not valid - the word aa appears more than once.
|
|
aa bb cc dd aaa is valid - aa and aaa count as different words.
|
|
|
|
The system's full passphrase list is available as your puzzle input. How many passphrases are valid?
|
|
|
|
*)
|
|
|
|
open Batteries
|
|
|
|
let validate_passphrase phrase =
|
|
let
|
|
words = String.split_on_char ' ' phrase
|
|
in
|
|
(List.length words) = (words |> Set.of_list |> Set.cardinal)
|
|
|
|
let parse_input input =
|
|
Enum.map validate_passphrase input
|
|
|> Enum.filter identity
|
|
|> Enum.count
|
|
|
|
let () =
|
|
Sys.argv.(1)
|
|
|> File.lines_of
|
|
|> parse_input
|
|
|> print_int
|
|
|