From 2786c716278286e2246138318d46e88fd4457492 Mon Sep 17 00:00:00 2001 From: Adam Millerchip Date: Fri, 25 Dec 2020 16:45:16 +0900 Subject: [PATCH] Day 25 Part 1 --- README.md | 2 +- day25/README | 26 ++++++++++++++++++++++++++ day25/day25part1.exs | 29 +++++++++++++++++++++++++++++ day25/input | 2 ++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 day25/README create mode 100644 day25/day25part1.exs create mode 100644 day25/input diff --git a/README.md b/README.md index 4b8e232..3cf6de6 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/day25/README b/day25/README new file mode 100644 index 0000000..3705f45 --- /dev/null +++ b/day25/README @@ -0,0 +1,26 @@ +Day 25 Notes + ++--------+ +| Part 1 | ++--------+ + +$ elixir day25part1.exs +4968512 + +Thoughts: + +Was a bit difficult to decipher the requirements, but after that the implementation was +simple enough. Wondering if there's a significance of the numbers 7 and 2020_12_27? + ++--------+ +| Part 2 | ++--------+ + +Arg. Need all the previous stars. So far I'm 10 under. + + ++------------------+ +| Overall Thoughts | ++------------------+ + + diff --git a/day25/day25part1.exs b/day25/day25part1.exs new file mode 100644 index 0000000..366784c --- /dev/null +++ b/day25/day25part1.exs @@ -0,0 +1,29 @@ +defmodule Day25Part1 do + def run do + [card_key, door_key] = + File.read!("input") + |> String.split("\n", trim: true) + |> Enum.map(&String.to_integer/1) + + door_loop_size = find_loop_size(1, door_key, 0) + + transform(1, card_key, door_loop_size) + |> IO.puts() + end + + def find_loop_size(public_key, public_key, size), do: size + + def find_loop_size(value, key, size) do + operation(value, 7) |> find_loop_size(key, size + 1) + end + + def transform(encryption_key, _subject_number, 0), do: encryption_key + + def transform(value, subject_number, size) do + operation(value, subject_number) |> transform(subject_number, size - 1) + end + + def operation(value, subject_number), do: rem(value * subject_number, 2020_12_27) +end + +Day25Part1.run() diff --git a/day25/input b/day25/input new file mode 100644 index 0000000..b1473b7 --- /dev/null +++ b/day25/input @@ -0,0 +1,2 @@ +10604480 +4126658