solve 2023 9.2
This commit is contained in:
parent
c14a908541
commit
28a7a098e3
2 changed files with 14 additions and 2 deletions
|
@ -9,7 +9,11 @@ aoc 2023, 9 do
|
|||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def p2(_input) do
|
||||
def p2(input) do
|
||||
input
|
||||
|> lines_of_integers()
|
||||
|> Enum.map(&prev_in_sequence/1)
|
||||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def next_in_sequence(xs) do
|
||||
|
@ -19,6 +23,14 @@ aoc 2023, 9 do
|
|||
|> Enum.sum()
|
||||
end
|
||||
|
||||
def prev_in_sequence(xs) do
|
||||
xs
|
||||
|> differentiate()
|
||||
|> Enum.map(&List.first/1)
|
||||
|> Enum.reverse()
|
||||
|> Enum.reduce(&(&1 - &2))
|
||||
end
|
||||
|
||||
def differentiate(xs) do
|
||||
xs
|
||||
|> Stream.iterate(&deltas/1)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
1. [2020] **17/50** 🌟
|
||||
1. [2021] **43/50** 🌟
|
||||
1. [2022] **14/50** 🌟
|
||||
1. [2023] **14/50** 🌟
|
||||
1. [2023] **15/50** 🌟
|
||||
|
||||
[2015]: ./2015
|
||||
[2017]: ./2017
|
||||
|
|
Loading…
Reference in a new issue