From a5b418cd4491a19d3683f601a75ce091f9482baa Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Thu, 10 Dec 2020 17:42:58 +0900 Subject: [PATCH] Day 10 Part 1 --- README.md | 2 +- day10/README | 37 +++++++++++++++++++++++++++++++++++++ day10/day10part1.exs | 23 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 day10/README create mode 100644 day10/day10part1.exs 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()