You finally reach the check-in desk. Unfortunately, their registration systems are currently offline, and they cannot check you in. Noticing the look on your face, they quickly add that tech support is already on the way! They even created all the room keys this morning; you can take yours now and give them your room deposit once the registration system comes back online.
The room key is a small RFID card. Your room is on the 25th floor and the elevators are also temporarily out of service, so it takes what little energy you have left to even climb the stairs and navigate the halls. You finally reach the door to your room, swipe your card, and - beep - the light turns red.
Read the full puzzle.
using System.Linq;
namespace AdventOfCode.Y2020.Day25;
[ProblemName("Combo Breaker")]
class Solution : Solver {
public object PartOne(string input) {
// https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
var numbers = input.Split("\n").Select(int.Parse).ToArray();
var mod = 20201227;
var pow = 0;
var subj = 7L;
var num = subj;
while (num != numbers[0] && num != numbers[1]) {
num = (num * subj) % mod;
pow++;
}
subj = num == numbers[0] ? numbers[1] : numbers[0];
num = subj;
while (pow > 0) {
num = (num * subj) % mod;
pow--;
}
return num;
}
}
Please ☆ my repo if you like it!