feat: 2.2

This commit is contained in:
s-prechtl 2025-12-02 14:53:23 +01:00
parent 9bdc305c90
commit 60f8fac516

View file

@ -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)