From a92e05928f1433b0a4405f62638c24ad12ac6743 Mon Sep 17 00:00:00 2001 From: Brechtje van Gessel Date: Tue, 2 Dec 2025 21:01:09 +0100 Subject: [PATCH] first attempt at day 2 part 2 --- brechtje/2/2-2.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 brechtje/2/2-2.py diff --git a/brechtje/2/2-2.py b/brechtje/2/2-2.py new file mode 100644 index 0000000..f4bc31f --- /dev/null +++ b/brechtje/2/2-2.py @@ -0,0 +1,50 @@ +from itertools import pairwise + +raw_input = open('input.txt', "r").read().split(',') +input = [] + +for item in raw_input: + input.append(item.split('-')) + +answer = 0 +invalid_numbers = [] + +for item in input: + for i in range(int(item[0]), int(item[1]) + 1): + str_i = str(i) + if len(str_i) % 2 == 0: + halfway = int(len(str_i)/2) + if str_i[0:halfway] == str_i[halfway:]: + answer += i + invalid_numbers.append(i) + continue + if len(str_i) % 3 == 0: + third = int(len(str_i)/3) + if str_i[0:third] == str_i[third:2 * third] == str_i[2 * third:]: + answer += i + invalid_numbers.append(i) + continue + if len(str_i) % 4 == 0: + quarter = int(len(str_i)/4) + if str_i[0:quarter] == str_i[quarter:halfway] == str_i[halfway:3 * quarter] == str_i[3 * quarter:]: + answer += i + invalid_numbers.append(i) + continue + if len(str_i) % 5 == 0: + fifth = int(len(str_i)/5) + if str_i[0:fifth] == str_i[fifth:2 * fifth] == str_i[2 * fifth:3 * fifth] == str_i[3 * fifth:4 * fifth] == str_i[4 * fifth:]: + answer += i + invalid_numbers.append(i) + continue + else: + all_the_same = True + for pair in pairwise(str_i): + if pair[0] != pair[1]: + all_the_same = False + break + if all_the_same: + answer += i + invalid_numbers.append(i) + +print(invalid_numbers) +print(answer) \ No newline at end of file