Day 25 Part 1

This commit is contained in:
Adam Millerchip 2020-12-25 16:45:16 +09:00
parent 0e55fb96df
commit 2786c71627
4 changed files with 58 additions and 1 deletions

View File

@ -2,7 +2,7 @@
My (attempted) solutions to [Advent of Code 2020](https://adventofcode.com/2020) in Elixir.
<img width="978" alt="image" src="https://user-images.githubusercontent.com/498229/103093696-6321ac80-463e-11eb-933c-8c6b23d15ee0.png">
<img width="982" alt="image" src="https://user-images.githubusercontent.com/498229/103125884-e8a16d00-46cf-11eb-854d-67e600374e82.png">
## Strategy

26
day25/README Normal file
View File

@ -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 |
+------------------+

29
day25/day25part1.exs Normal file
View File

@ -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()

2
day25/input Normal file
View File

@ -0,0 +1,2 @@
10604480
4126658