From fe439e8c33a8ed0b5c70491ba950a88e24e1a217 Mon Sep 17 00:00:00 2001 From: tebarius Date: Mon, 8 Dec 2025 20:20:08 +0100 Subject: [PATCH] 2-02 --- 02/02-2.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 02/02-2.py diff --git a/02/02-2.py b/02/02-2.py new file mode 100644 index 0000000..709e307 --- /dev/null +++ b/02/02-2.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# file = "./ex.txt" +file = "./input.txt" + +def is_repetition(s: str) -> bool: + n = len(s) + if n < 2: + return False + # mögliche Längen des Teilstrings durchprobieren + for l in range(1, n // 2 + 1): + if n % l != 0: + continue # Länge teilt die Gesamtlänge nicht + block = s[:l] + if block * (n // l) == s: + return True + return False + + + +if __name__ == "__main__": + solution = 0 + input_file = open(file, "r") + for line in input_file: + line = line.strip() + if line == "": + continue + range_list = line.split(",") + for r in range_list: + a,b = r.split("-") + for i in range(int(a),int(b)+1): + if is_repetition(str(i)): + solution += i + print(f"Solution: {solution}")