Skip to content

Commit 85b4298

Browse files
committed
AoC 2020, day 5
1 parent 55d51b3 commit 85b4298

File tree

2 files changed

+785
-0
lines changed

2 files changed

+785
-0
lines changed

2020/05/boarding.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python3
2+
def seat_id(boarding_pass):
3+
boarding_pass = boarding_pass.replace('F', '0').replace('B', '1').replace('L', '0').replace('R', '1')
4+
boarding_pass = int(boarding_pass, 2)
5+
row = boarding_pass >> 3
6+
seat = boarding_pass & 7
7+
return (row * 8) + seat
8+
9+
def main():
10+
passes = []
11+
with open('input') as f:
12+
passes = [line.strip() for line in f]
13+
14+
seat_ids = sorted([seat_id(boarding_pass) for boarding_pass in passes])
15+
highest_id = max(seat_ids)
16+
print(highest_id)
17+
18+
lowest_id = min(seat_ids)
19+
for seat in range(lowest_id, highest_id):
20+
if seat not in seat_ids:
21+
print(seat)
22+
23+
if __name__ == "__main__":
24+
main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy