From 68615a9ad2c942254135cffb00cf25a84a3b1356 Mon Sep 17 00:00:00 2001 From: Prefetch Date: Sat, 31 Dec 2022 22:21:39 +0100 Subject: Initial commit --- 25/input.txt | 1 + 25/main.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 25/test.py | 17 +++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 25/input.txt create mode 100755 25/main.py create mode 100755 25/test.py (limited to '25') diff --git a/25/input.txt b/25/input.txt new file mode 100644 index 0000000..c5c38e6 --- /dev/null +++ b/25/input.txt @@ -0,0 +1 @@ +To continue, please consult the code grid in the manual. Enter the code at row 2947, column 3029. diff --git a/25/main.py b/25/main.py new file mode 100755 index 0000000..48ca1f7 --- /dev/null +++ b/25/main.py @@ -0,0 +1,47 @@ +#!/usr/bin/python + + + +def coord_list(until): + return result + + + +def solve_part1(until): + # Generate a list of table (row, col) coordinates in the order + # that are filled by the algorithm described in the puzzle text. + coords = [] + r = 1 + c = 0 + while (r, c) != until: + if r == 1: + r = c + 1 + c = 1 + else: + r -= 1 + c += 1 + coords.append((r, c)) + + code = 20151125 # first code is given + for i in range(1, len(coords)): + code *= 252533 + code %= 33554393 + + return code + + + +def main(): + # Read target coordinate from input text file + with open("input.txt", "r") as f: + words = f.read().split() + row = int(words[-3].rstrip(",")) + col = int(words[-1].rstrip(".")) + coord = (row, col) + + print("Part 1 solution:", solve_part1(coord)) # 19980801 for me + + + +if __name__ == "__main__": + main() diff --git a/25/test.py b/25/test.py new file mode 100755 index 0000000..5b34e3e --- /dev/null +++ b/25/test.py @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import unittest + +import main + + + +class ExamplesPart1(unittest.TestCase): + def test_example1(self): + until = (1, 6) + self.assertEqual(main.solve_part1(until), 33511524) + + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3