zerosleeps

Since 2010

Advent of Code 2020 day 25

Advent of Code 2020 day 25. A bit overcooked considering (spoiler) there’s no part 2 🙁

Very happy to have gotten all 50 stars this year. With the exception of day 10 part 2 the code is all my own. Yes I’ve used hints and pointers, and I’m already embarrassed by some of my solutions, but that all comes hand-in-hand with being a developer, right?

Great fun. Was nice to have a little puzzle to look forward to at the end of each day.

class Handshake:
    def __init__(self, public_key):
        self.public_key = public_key
        self.value = 1
        self.loop_size = self.get_loop_size()

    def transform(self):
        self.value = (self.value * 7) % 20201227

    def private_key(self, public_key):
        value = 1
        for _ in range(self.loop_size):
            value = (value * public_key) % 20201227
        return value

    def get_loop_size(self):
        loop_size = 0
        while self.value != self.public_key:
            self.transform()
            loop_size += 1
        return loop_size

def part_one(public_keys):
    card = Handshake(public_keys[0])
    return card.private_key(public_keys[1])

if __name__ == '__main__':
    print(f"Part one: {part_one([5764801, 17807724])}")