Solve 2020 day 5
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
from lib import get_data, Grid2D
|
||||
from lib import get_data
|
||||
|
||||
required = [
|
||||
required = [
|
||||
"byr",
|
||||
"iyr",
|
||||
"eyr",
|
||||
"hgt",
|
||||
"hcl",
|
||||
"ecl",
|
||||
"pid",]
|
||||
"pid",
|
||||
]
|
||||
|
||||
|
||||
# hgt (Height) - a number followed by either cm or in:
|
||||
#
|
||||
#
|
||||
# If cm, the number must be at least 150 and at most 193.
|
||||
# If in, the number must be at least 59 and at most 76.
|
||||
|
||||
|
||||
40
2020/d5.py
Normal file
40
2020/d5.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from lib import get_data
|
||||
|
||||
|
||||
def part_1(data):
|
||||
rs = []
|
||||
for line in data.splitlines():
|
||||
rl, ru = 0, 127
|
||||
cl, cu = 0, 7
|
||||
for c in line.strip():
|
||||
rh = (ru - rl) // 2
|
||||
ch = (cu - cl) // 2
|
||||
if c == "B":
|
||||
rl = rl + rh + 1
|
||||
elif c == "F":
|
||||
ru = rl + rh
|
||||
elif c == "R":
|
||||
cl = cl + ch + 1
|
||||
elif c == "L":
|
||||
cu = cl + ch
|
||||
else:
|
||||
assert False
|
||||
assert rl == ru
|
||||
assert cl == cu
|
||||
r_new = rl * 8 + cl
|
||||
rs.append(r_new)
|
||||
|
||||
print(max(rs))
|
||||
rs = sorted(rs)
|
||||
for i in range(len(rs) - 1):
|
||||
if rs[i] + 1 != rs[i + 1]:
|
||||
print(rs[i] + 1)
|
||||
|
||||
|
||||
def main():
|
||||
data = get_data(__file__)
|
||||
part_1(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user