2025(03): make code a bit better

And clean up part 2 of day 2, add testinput for day 1.
This commit is contained in:
2025-12-03 09:03:02 +01:00
parent 5f102fc380
commit 06d839fe7e
3 changed files with 22 additions and 50 deletions

View File

@ -1,24 +1,16 @@
def is_invalid_id(num):
# print("Testing", num)
num_str = str(num)
num_len = len(num_str)
for period in range(1, num_len):
# print("period =", period)
# Period should be a factor of num_len
if num_len % period != 0:
continue
# Start with True, make False when it fails
palin = True
for idx in range(period, num_len, period):
# print("idx =", idx)
# print(num_str[:period], "=?=", num_str[idx:idx + period])
if num_str[:period] != num_str[idx:idx + period]:
# print(False)
palin = False
# print(False)
if palin:
# print("Returning palin")
return True
# No period has yielded repetition:
@ -43,22 +35,5 @@ if __name__ == "__main__":
print(num, "is a palindrome thing")
illegal_counter += 1
illegal_sum += num
# num_str = str(num)
# num_len = len(num_str)
# palin = False
# # Look at the different options for lengths
# for partlen in range(2, num_len + 1):
# # Only continue if it's a factor
# if num_len % partlen != 0:
# continue
# for idx in range(partlen, num_len, partlen):
# if num_str[:partlen] == num_str[idx:idx + partlen]:
# continue
# palin = True
# break
# if palin:
# print(num_str, "is a palindrome thing")
# illegal_counter += 1
# illegal_sum += num
print(illegal_counter, illegal_sum)