diff options
author | H.J <thechairman@thechairman.info> | 2024-06-03 17:16:30 -0400 |
---|---|---|
committer | H.J <thechairman@thechairman.info> | 2024-06-03 17:16:30 -0400 |
commit | 23c7ca166ac87a339c6ee6ed71aed41afefb5513 (patch) | |
tree | 904bea816aa94775084dc08ea740ac692112184a /aoc2017-gleam/src/aoc_2017/day_4.gleam | |
parent | a679186bed8e5e284604fab7ef8ac932b66d4d51 (diff) | |
download | gleam_aoc-23c7ca166ac87a339c6ee6ed71aed41afefb5513.tar.gz gleam_aoc-23c7ca166ac87a339c6ee6ed71aed41afefb5513.zip |
gleam 2017 up to day 7 part 1
Diffstat (limited to 'aoc2017-gleam/src/aoc_2017/day_4.gleam')
-rw-r--r-- | aoc2017-gleam/src/aoc_2017/day_4.gleam | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/aoc2017-gleam/src/aoc_2017/day_4.gleam b/aoc2017-gleam/src/aoc_2017/day_4.gleam new file mode 100644 index 0000000..9bc4f9a --- /dev/null +++ b/aoc2017-gleam/src/aoc_2017/day_4.gleam @@ -0,0 +1,31 @@ +import gleam/list +import gleam/string + +pub fn parse(input: String) -> List(List(String)) { + use row <- list.map(string.split(input, "\n")) + string.split(row, " ") +} + +pub fn pt_1(input: List(List(String))) { + use acc, passwords <- list.fold(input, 0) + case passwords == list.unique(passwords) { + True -> acc + 1 + False -> acc + } +} + +pub fn pt_2(input: List(List(String))) { + use acc, passwords <- list.fold(input, 0) + let sorted_passwords = list.map(passwords, sort_graphemes) + case sorted_passwords == list.unique(sorted_passwords) { + True -> acc + 1 + False -> acc + } +} + +fn sort_graphemes(word: String) -> String { + word + |> string.to_graphemes + |> list.sort(string.compare) + |> string.concat +} |