diff options
author | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
commit | 8e313e2614c7a0fe5af924febdbacc650e33835e (patch) | |
tree | 63426b6942ceebe17708140c972a7d7451bd2f74 /5_2020.py | |
download | aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip |
intial
Diffstat (limited to '5_2020.py')
-rw-r--r-- | 5_2020.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/5_2020.py b/5_2020.py new file mode 100644 index 0000000..fed1200 --- /dev/null +++ b/5_2020.py @@ -0,0 +1,50 @@ +import fileinput +import re + +p1 = None +p2 = None + +ids = set() +lines = list(fileinput.input()) +lines.append("") +for line in lines: + line = line.strip() + # FBFBBFFRLR + # Translate to binary: row=0101100 + # 32+8+4 = row 44 + # col=101 + # 4+1 = col 5 + + row = 0 + rp = 64 + + col = 0 + cp = 4 + + for c in line: + if c == "B": + row += rp + rp /= 2 + elif c == "F": + rp /= 2 + + if c == "R": + col += cp + cp /= 2 + elif c == "L": + cp /= 2 + + seat_id = row * 8 + col + ids.add(seat_id) + if p1: + p1 = max(p1, seat_id) + else: + p1 = seat_id + +for id_ in sorted(ids): + if id_ + 1 not in ids and id_ + 2 in ids: + assert p2 is None + p2 = id_ + 1 + +print(p1) +print(p2) |