diff --git a/README.md b/README.md index a07744b..2b3af66 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ My (attempted) solutions to [Advent of Code 2020](https://adventofcode.com/2020) in Elixir. -image +image ## Strategy diff --git a/day10/README b/day10/README new file mode 100644 index 0000000..08e40b4 --- /dev/null +++ b/day10/README @@ -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. diff --git a/day10/day10part1.exs b/day10/day10part1.exs new file mode 100644 index 0000000..f5eaad2 --- /dev/null +++ b/day10/day10part1.exs @@ -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()