diff options
author | Simponic <loganhunt@simponic.xyz> | 2022-12-12 00:04:40 -0700 |
---|---|---|
committer | Simponic <loganhunt@simponic.xyz> | 2022-12-12 00:04:40 -0700 |
commit | 60e8a827266f5282008a168ee73df2aff8966f3c (patch) | |
tree | a5c528488b5aa87f7e78ee3f7aa86e4b2e5719a1 /day-05 | |
parent | 7db39f82bfcd196f840bf3c2a820331c6a04d570 (diff) | |
download | aoc-60e8a827266f5282008a168ee73df2aff8966f3c.tar.gz aoc-60e8a827266f5282008a168ee73df2aff8966f3c.zip |
Day 05 and 06
Diffstat (limited to 'day-05')
-rw-r--r-- | day-05/sol.exs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/day-05/sol.exs b/day-05/sol.exs new file mode 100644 index 0000000..e1dab2b --- /dev/null +++ b/day-05/sol.exs @@ -0,0 +1,28 @@ +defmodule Solution do + def solve(input, chunk) do + (String.split(input, "", trim: true) + |> Enum.chunk_every(chunk, 1, :discard) + |> Enum.map(fn window -> + Enum.reduce(window, %{}, fn char, acc -> + Map.put(acc, char, Map.get(acc, char, 0) + 1) + end) + end) + |> Enum.find_index(fn letter_counts -> + Enum.all?(letter_counts, fn {_key, value} -> + value == 1 + end) + end)) + chunk + end + + def main do + input = File.read!("input") + + solve(input, 4) + |> IO.inspect() + + solve(input, 14) + |> IO.inspect() + end +end + +Solution.main() |