Merge Bob's branch into benchmark branch
commit
08f116ec57
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
|
||||
|
||||
def check_id(start, end):
|
||||
false_ids = []
|
||||
for id in range(int(start), int(end)+1):
|
||||
id_str = str(id)
|
||||
id_str_len = len(id_str)
|
||||
if id_str_len % 2 == 0:
|
||||
h1 = id_str[:id_str_len//2]
|
||||
h2 = id_str[id_str_len//2:]
|
||||
if h1 == h2:
|
||||
false_ids.append(id)
|
||||
|
||||
return false_ids
|
||||
|
||||
|
||||
|
||||
def read_input(filename):
|
||||
id_ranges = []
|
||||
for line in open(filename).read().splitlines():
|
||||
for id_range in line.split(","):
|
||||
start = id_range.split("-")[0]
|
||||
end = id_range.split("-")[1]
|
||||
|
||||
id_ranges.append((start,end))
|
||||
return id_ranges
|
||||
|
||||
|
||||
# filename = "day02/example_input" # 1227775554
|
||||
filename = "day02/input" # 23560874270
|
||||
id_ranges = read_input(filename)
|
||||
|
||||
|
||||
adding = 0
|
||||
for id_range in id_ranges:
|
||||
for false_id in check_id(id_range[0], id_range[1]):
|
||||
adding += false_id
|
||||
|
||||
|
||||
print(f"Added total of false IDs: {adding}")
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
|
||||
|
||||
|
||||
def check_id(start_id, end_id):
|
||||
false_ids = []
|
||||
for id in range(int(start_id), int(end_id)+1):
|
||||
id_str = str(id)
|
||||
id_str_len = len(id_str)
|
||||
|
||||
for substr_len in range(1,(id_str_len//2)+1):
|
||||
if id_str_len % substr_len > 0:
|
||||
# Substring being checked must fit a whole number of times
|
||||
continue
|
||||
|
||||
dup = False
|
||||
# Substring position is determined by the amount of times the substring fits in the string
|
||||
# That makes up the range to be checked (as multipliet with the substring length)
|
||||
for substr_pos in range(1, id_str_len // substr_len):
|
||||
h1 = id_str[:substr_len]
|
||||
|
||||
# Get the substring at right position, and only with size of substring
|
||||
h2 = id_str[substr_len*substr_pos:][:substr_len]
|
||||
if h1 != h2:
|
||||
dup = False
|
||||
break
|
||||
else:
|
||||
dup = True
|
||||
|
||||
if dup:
|
||||
false_ids.append(id)
|
||||
break
|
||||
|
||||
|
||||
return false_ids
|
||||
|
||||
|
||||
|
||||
def read_input(filename):
|
||||
id_ranges = []
|
||||
for line in open(filename).read().splitlines():
|
||||
for id_range in line.split(","):
|
||||
start = id_range.split("-")[0]
|
||||
end = id_range.split("-")[1]
|
||||
|
||||
id_ranges.append((start,end))
|
||||
return id_ranges
|
||||
|
||||
|
||||
# filename = "day02/my_example_input" #
|
||||
# filename = "day02/example_input" # 4174379265
|
||||
filename = "day02/input" # 44143124633
|
||||
id_ranges = read_input(filename)
|
||||
|
||||
|
||||
adding = 0
|
||||
for id_range in id_ranges:
|
||||
for false_id in check_id(id_range[0], id_range[1]):
|
||||
adding += false_id
|
||||
|
||||
|
||||
print(f"Added total of false IDs: {adding}")
|
||||
|
|
@ -0,0 +1 @@
|
|||
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||
|
|
@ -0,0 +1 @@
|
|||
990244-1009337,5518069-5608946,34273134-34397466,3636295061-3636388848,8613701-8663602,573252-688417,472288-533253,960590-988421,7373678538-7373794411,178-266,63577667-63679502,70-132,487-1146,666631751-666711926,5896-10827,30288-52204,21847924-21889141,69684057-69706531,97142181-97271487,538561-555085,286637-467444,93452333-93519874,69247-119122,8955190262-8955353747,883317-948391,8282803943-8282844514,214125-236989,2518-4693,586540593-586645823,137643-211684,33-47,16210-28409,748488-837584,1381-2281,1-19
|
||||
|
|
@ -0,0 +1 @@
|
|||
12345678-12345679
|
||||
Loading…
Reference in New Issue