Day 18 Part 2

This commit is contained in:
Adam Millerchip 2020-12-20 15:31:28 +09:00
parent 7a46852b23
commit d607504faf
4 changed files with 461 additions and 3 deletions

View file

@ -2,7 +2,7 @@
My (attempted) solutions to [Advent of Code 2020](https://adventofcode.com/2020) in Elixir. My (attempted) solutions to [Advent of Code 2020](https://adventofcode.com/2020) in Elixir.
<img width="983" alt="image" src="https://user-images.githubusercontent.com/498229/102591989-31987500-4156-11eb-8d21-2ea88021c9b0.png"> <img width="978" alt="image" src="https://user-images.githubusercontent.com/498229/102717151-cdc3a700-4323-11eb-930e-613465f503d1.png">
## Strategy ## Strategy

View file

@ -5,7 +5,7 @@ Day 18 Notes
+--------+ +--------+
$ elixir day18part1.exs $ elixir day18part1.exs
<will add later> 21347713555555
Thoughts: Thoughts:
Since the order of precedence is the same, we can walk the token list, building up a left operand Since the order of precedence is the same, we can walk the token list, building up a left operand
@ -18,17 +18,48 @@ use recursion to resolve the group, and push the result back onto the beginning
+--------+ +--------+
$ elixir day18part2.exs $ elixir day18part2.exs
275011754427339
Thoughts: Thoughts:
Now the order of precedence is relevant, so can no longer just walk the token list, need to know the Now the order of precedence is relevant, so can no longer just walk the token list, need to know the
full context. full context.
Addition basically becomes implicit brackets. Addition basically becomes implicit brackets.
Will do this part later.
If we have a * operand, for example 2 in 1 * 2 + 3, we can't apply * without first looking ahead
to see if there is a higher precedence +.
I decided to build an Abstract Syntax Tree, and then evaluate it. To build the AST, I used the
following strategy:
1. First pass - resolve + operations.
For numbers and * operators, store them in a _later_ buffer until we know what to do with them.
For + operators, we can safely add the previous operand in the later buffer with the next
operand.
Recurse into brackets.
2. Second pass - resolve * operations.
The second pass runs at the end of any bracket group, or the end of string.
All the additions have been handled, so can safely just multiply these.
3. Finally, evaluate the AST recursively to get the answer.
I spent far too long on this and it was very difficult to debug. The examples provided were very
useful and hit a lot of edge cases. Again, I really struggle to reason about any form of recursion
that is more complex than a simple loop. There were lots of IO.inspects going on in the development
of this. The answer can probably be simplified further, but I'm pretty happy that I managed to
implement it using an AST with multiple function clauses as a proof of concept.
It's pretty hard to tell what all the clauses do at first glance, but then that would be true for a
a huge function with lots of embedded conditionals too. I will definitely be seeing how other people
implemented this one.
+------------------+ +------------------+
| Overall Thoughts | | Overall Thoughts |
+------------------+ +------------------+
Part 1 was very simple due to it not having precedence, and I think it can be implemented nicely in
Elixir. Part 2's deceptively simple requirements were surprisingly difficult - probably because of
the approach I took with building an AST.
Considering I have less time to spend on the last week of questions, I decided to chip away at this
one over a few days. Now I'm spoilt for choice for which one to do next! 17, 19, or 20...

55
day18/day18part2.exs Normal file
View file

@ -0,0 +1,55 @@
defmodule Day18Part2 do
def run do
File.stream!("input")
|> Stream.map(&tokenize/1)
|> Stream.map(&to_ast/1)
|> Stream.map(&evaluate/1)
|> Enum.sum()
|> IO.puts()
end
def tokenize(line) do
line
|> String.graphemes()
|> Stream.reject(fn char -> char in [" ", "\n"] end)
|> Enum.map(fn
symbol when symbol in ["*", "+", "(", ")"] -> symbol
num -> {:num, String.to_integer(num)}
end)
end
def to_ast(line), do: to_ast(line, nil, nil, [])
def to_ast([], ast, nil, []), do: ast
def to_ast([], ast, nil, later), do: ast_later(Enum.reverse([ast | later]), nil, nil)
def to_ast(["+" | rest], left, nil, later), do: to_ast(rest, left, "+", later)
def to_ast(["*" | rest], left, nil, later), do: to_ast(rest, nil, nil, ["*", left | later])
def to_ast(["(" | rest], nil, op, later) do
{new_left, rest} = to_ast(rest)
to_ast(rest, new_left, op, later)
end
def to_ast(["(" | rest], left, op, later) do
{new_left, rest} = to_ast(rest)
to_ast([left | rest], new_left, op, later)
end
def to_ast([")" | rest], ast, nil, later) do
ast = ast_later(Enum.reverse([ast | later]), nil, nil)
{ast, rest}
end
def to_ast([ast | rest], nil, nil, later), do: to_ast(rest, ast, nil, later)
def to_ast([right | rest], left, "+", later), do: to_ast(rest, {"+", left, right}, nil, later)
def ast_later([], ast, nil), do: ast
def ast_later(["*" | rest], left, nil), do: ast_later(rest, left, "*")
def ast_later([left | rest], nil, nil), do: ast_later(rest, left, nil)
def ast_later([right | rest], left, "*"), do: ast_later(rest, {"*", left, right}, nil)
def evaluate({:num, num}), do: num
def evaluate({"+", left, right}), do: evaluate(left) + evaluate(right)
def evaluate({"*", left, right}), do: evaluate(left) * evaluate(right)
end
Day18Part2.run()

372
day18/input Normal file
View file

@ -0,0 +1,372 @@
(7 * 7 + (2 + 5 * 7 * 8 + 2) + 4 + 2) * 5 * ((9 * 3 * 9 + 8 + 3) + (9 + 4 + 7 + 8) * (2 + 5))
((7 * 7 * 9 * 5 + 5) + 9 * (9 + 7 + 9 + 5 * 9 + 6)) * 7 + 8 * 6 + 4 * 4
6 * (9 + 8 + 6 * 8 + (3 * 2 + 4)) + 4
(7 * 5) + 4 + 7
3 * (6 * 8 + 5 + (8 * 9 * 3 + 7 * 4) + 8) * 3 + 2 * 5
(4 * 3 * (7 * 2 + 2 + 6 + 5) * 4 + 8) + 9 * (3 + 2 + (5 * 2)) * (2 + (2 * 9 * 3) * 5 * (7 * 5 + 6 * 2 * 7) + 5 + 5)
4 + (6 * 7 * (5 * 7) * 4) * 2 + (4 + 8 * 5) + ((5 * 7 * 4 * 7) + 3 * 5 + (6 + 9 + 3 + 2) + 2 * 5) * 7
2 + 4 + ((4 * 4 + 3 + 7 * 4) + 4 + (2 * 5 + 9) + 8 + 4 + 7) + 5 * 5 + 9
7 * (7 * 3 + 2 * 9 + 7 + 7) * 3 * 4
8 + 4 + 3 + 9 + 8
2 + 2 + 6 * (5 + 9 * 3 * 7) * 6
(3 * 9 * 4 + 2 * 6) * 8
8 + 6 * 4 + (7 + 7 + 8 + 9) * ((2 + 3 + 7 + 6 * 3) + 6 * 6)
7 + 9 * 3 * 9
((9 + 6) + 7 + 6) + (2 + 5 * 3 * 2 * 7)
(8 * 7 + 6 * 6 * 7 + 3) + 5
9 * (8 + 3) * 9 + (4 + 8 * (3 + 9 + 5)) * 9
9 + (5 * 2 * 4 + 3) * 3 + 6
(3 + 7 + 2 + 3)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