Day 10 Part 1
This commit is contained in:
parent
0e60744957
commit
a5b418cd44
3 changed files with 61 additions and 1 deletions
|
@ -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="975" alt="image" src="https://user-images.githubusercontent.com/498229/101621087-a71a8c00-3a58-11eb-9cf5-ca816dbba6ee.png">
|
<img width="975" alt="image" src="https://user-images.githubusercontent.com/498229/101746064-b0663000-3b0e-11eb-81bd-92597dba329e.png">
|
||||||
|
|
||||||
## Strategy
|
## Strategy
|
||||||
|
|
||||||
|
|
37
day10/README
Normal file
37
day10/README
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
Day 10 Notes
|
||||||
|
|
||||||
|
+--------+
|
||||||
|
| Part 1 |
|
||||||
|
+--------+
|
||||||
|
|
||||||
|
$ elixir day10part1.exs
|
||||||
|
**solved - will add answer after part 2 is complete**
|
||||||
|
|
||||||
|
Thoughts:
|
||||||
|
|
||||||
|
Noticed that the questions rely on you finding some insight into the data, rather than just
|
||||||
|
implementing exactly what the instructions say.
|
||||||
|
|
||||||
|
In this case, we just need to sort the data, and compute the difference between all the pairs.
|
||||||
|
|
||||||
|
|
||||||
|
+-------------------+
|
||||||
|
| Part 2 [UNSOLVED] |
|
||||||
|
+-------------------+
|
||||||
|
|
||||||
|
$ elixir day10part2.exs
|
||||||
|
...
|
||||||
|
|
||||||
|
Thoughts:
|
||||||
|
|
||||||
|
So far defeated on this one. I'm obviously missing a fundamental trick.
|
||||||
|
|
||||||
|
I went down a massive rabbit hold calculating combinations, which didn't pay off.
|
||||||
|
Will leave this for now, and maybe come back to it later.
|
||||||
|
|
||||||
|
|
||||||
|
+------------------+
|
||||||
|
| Overall Thoughts |
|
||||||
|
+------------------+
|
||||||
|
|
||||||
|
Not committing the input for now, in case somebody decides to @ me my answer or something.
|
23
day10/day10part1.exs
Normal file
23
day10/day10part1.exs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
defmodule Day10Part1 do
|
||||||
|
def run do
|
||||||
|
input =
|
||||||
|
File.read!("input")
|
||||||
|
|> String.split("\n", trim: true)
|
||||||
|
|> Enum.map(&String.to_integer/1)
|
||||||
|
|
||||||
|
max = Enum.max(input)
|
||||||
|
outlet = 0
|
||||||
|
built_in = max + 3
|
||||||
|
|
||||||
|
jolts =
|
||||||
|
[outlet, built_in | input]
|
||||||
|
|> Enum.sort()
|
||||||
|
|> Enum.chunk_every(2, 1, :discard)
|
||||||
|
|> Enum.map(fn [a, b] -> b - a end)
|
||||||
|
|> Enum.frequencies()
|
||||||
|
|
||||||
|
IO.puts(jolts[1] * jolts[3])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Day10Part1.run()
|
Loading…
Reference in a new issue