Solve 2020 day 5

This commit is contained in:
felixm 2024-08-29 06:10:05 -04:00
parent 631205086d
commit 305fe0b325
3 changed files with 47 additions and 5 deletions

View File

@ -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
View 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()

View File

@ -137,7 +137,8 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 2: 4:47 (no leaderboard, you can tell it's getting faster)
- Day 3: 7:06 (way too slow, lol; time to take it seriously)
- Day 4: 14:30 (yo, I am just too slow)
- Day 5:
- Day 5: 11:53 (not competitive)
- Day 6:
## AoC 2022