1
0
Fork 0

solve 2023 13.2

This commit is contained in:
sloane 2023-12-13 09:20:38 -05:00
parent 29f788f17b
commit 0986f75f68
No known key found for this signature in database
2 changed files with 15 additions and 9 deletions

View file

@ -10,34 +10,40 @@ aoc 2023, 13 do
|> Enum.sum()
end
def p2(_input) do
def p2(input) do
input
|> String.split("\n\n")
|> Enum.map(&lines_of_chars/1)
|> Enum.map(&summarize(&1, 1))
|> Enum.sum()
end
def summarize(lines) do
vertical_line_of_reflection = find_reflection_index(lines)
horizontal_line_of_reflection = lines |> transpose() |> find_reflection_index()
def summarize(lines, smudges \\ 0) do
vertical_line_of_reflection = find_reflection_index(lines, smudges)
horizontal_line_of_reflection = lines |> transpose() |> find_reflection_index(smudges)
summary = vertical_line_of_reflection + 100 * horizontal_line_of_reflection
summary
end
def find_reflection_index(lines) do
def find_reflection_index(lines, smudges) do
len = lines |> List.first() |> length()
idx =
for i <- 1..(len - 1) do
lines
|> Enum.all?(fn line ->
|> Enum.map(fn line ->
line
|> Enum.split(i)
|> Tuple.to_list()
|> map_list([&Enum.reverse/1, &id/1])
|> Enum.zip_with(&apply(Kernel, :==, &1))
|> Enum.all?(is?(true))
|> Enum.count(is?(false))
end)
|> Enum.sum()
end
|> Enum.find_index(is?(true))
|> Enum.find_index(is?(smudges))
if idx, do: idx + 1, else: 0
end

View file

@ -14,7 +14,7 @@
1. [2020] **17/50** 🌟
1. [2021] **43/50** 🌟
1. [2022] **14/50** 🌟
1. [2023] **18/50** 🌟
1. [2023] **19/50** 🌟
[2015]: ./2015
[2017]: ./2017