feat: 2.2
This commit is contained in:
parent
9bdc305c90
commit
60f8fac516
1 changed files with 19 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue