Day 5
This commit is contained in:
24
day05/part2.py
Normal file
24
day05/part2.py
Normal file
@@ -0,0 +1,24 @@
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
|
||||
reserved = []
|
||||
|
||||
|
||||
def parse_binary_string(string: str, ones):
|
||||
length = len(string) - 1
|
||||
cnt = 0
|
||||
for idx, val in enumerate(string):
|
||||
cnt += 2 ** (length-idx) if val == ones else 0
|
||||
return cnt
|
||||
|
||||
|
||||
for line in lines:
|
||||
row = parse_binary_string(line[:7], ones="B")
|
||||
col = parse_binary_string(line[7:], ones="R")
|
||||
num = row * 8 + col
|
||||
reserved.append(num)
|
||||
|
||||
reserved = sorted(reserved)
|
||||
|
||||
for i in range(len(reserved) - 1):
|
||||
if reserved[i+1] - reserved[i] == 2:
|
||||
print(reserved[i]+1)
|
||||
Reference in New Issue
Block a user