36 lines
878 B
Python
36 lines
878 B
Python
#!/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}")
|