solve 2023 13.2
This commit is contained in:
parent
29f788f17b
commit
0986f75f68
2 changed files with 15 additions and 9 deletions
|
@ -10,34 +10,40 @@ aoc 2023, 13 do
|
||||||
|> Enum.sum()
|
|> Enum.sum()
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def summarize(lines) do
|
def summarize(lines, smudges \\ 0) do
|
||||||
vertical_line_of_reflection = find_reflection_index(lines)
|
vertical_line_of_reflection = find_reflection_index(lines, smudges)
|
||||||
horizontal_line_of_reflection = lines |> transpose() |> find_reflection_index()
|
horizontal_line_of_reflection = lines |> transpose() |> find_reflection_index(smudges)
|
||||||
|
|
||||||
summary = vertical_line_of_reflection + 100 * horizontal_line_of_reflection
|
summary = vertical_line_of_reflection + 100 * horizontal_line_of_reflection
|
||||||
|
|
||||||
summary
|
summary
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_reflection_index(lines) do
|
def find_reflection_index(lines, smudges) do
|
||||||
len = lines |> List.first() |> length()
|
len = lines |> List.first() |> length()
|
||||||
|
|
||||||
idx =
|
idx =
|
||||||
for i <- 1..(len - 1) do
|
for i <- 1..(len - 1) do
|
||||||
lines
|
lines
|
||||||
|> Enum.all?(fn line ->
|
|> Enum.map(fn line ->
|
||||||
line
|
line
|
||||||
|> Enum.split(i)
|
|> Enum.split(i)
|
||||||
|> Tuple.to_list()
|
|> Tuple.to_list()
|
||||||
|> map_list([&Enum.reverse/1, &id/1])
|
|> map_list([&Enum.reverse/1, &id/1])
|
||||||
|> Enum.zip_with(&apply(Kernel, :==, &1))
|
|> Enum.zip_with(&apply(Kernel, :==, &1))
|
||||||
|> Enum.all?(is?(true))
|
|> Enum.count(is?(false))
|
||||||
end)
|
end)
|
||||||
|
|> Enum.sum()
|
||||||
end
|
end
|
||||||
|> Enum.find_index(is?(true))
|
|> Enum.find_index(is?(smudges))
|
||||||
|
|
||||||
if idx, do: idx + 1, else: 0
|
if idx, do: idx + 1, else: 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
1. [2020] **17/50** 🌟
|
1. [2020] **17/50** 🌟
|
||||||
1. [2021] **43/50** 🌟
|
1. [2021] **43/50** 🌟
|
||||||
1. [2022] **14/50** 🌟
|
1. [2022] **14/50** 🌟
|
||||||
1. [2023] **18/50** 🌟
|
1. [2023] **19/50** 🌟
|
||||||
|
|
||||||
[2015]: ./2015
|
[2015]: ./2015
|
||||||
[2017]: ./2017
|
[2017]: ./2017
|
||||||
|
|
Loading…
Reference in a new issue