diff --git a/2025/Day2/src/main.py b/2025/Day2/src/main.py index fe00f0e..ca3baca 100644 --- a/2025/Day2/src/main.py +++ b/2025/Day2/src/main.py @@ -1,10 +1,27 @@ def is_repeated(id: str) -> bool: - #print(id[:len(id)//2], id[len(id)//2:]) if id[:len(id)//2] == id[len(id)//2:]: return True return False +def is_repeated_n(id: str) -> bool: + max_bundle_size = len(id) // 2 + for bundle_size in range(1, max_bundle_size + 1): + if len(id) % bundle_size != 0: + continue + + for pos in range(bundle_size, len(id) - bundle_size + 1, bundle_size): + prev_pos = pos - bundle_size + + if id[prev_pos:pos] != id[pos:pos+bundle_size]: + break + + if pos+bundle_size == len(id): + return True + + return False + + if __name__ == '__main__': count = 0 @@ -17,7 +34,7 @@ if __name__ == '__main__': if str(id)[0] == '0': continue - if is_repeated(str(id)): + if is_repeated_n(str(id)): count += id print(count)