2020: d05: ex1: add solution
This commit is contained in:
parent
359dfe5d54
commit
a8ffb5bf66
35
2020/d05/ex1/ex1.py
Executable file
35
2020/d05/ex1/ex1.py
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def seat_id(boarding_pass: str) -> int:
|
||||
min_x = 0
|
||||
max_x = 128
|
||||
min_y = 0
|
||||
max_y = 8
|
||||
|
||||
for char in boarding_pass:
|
||||
if char == "F":
|
||||
max_x = (min_x + max_x) // 2
|
||||
elif char == "B":
|
||||
min_x = (min_x + max_x) // 2
|
||||
elif char == "L":
|
||||
max_y = (min_y + max_y) // 2
|
||||
elif char == "R":
|
||||
min_y = (min_y + max_y) // 2
|
||||
return min_x * 8 + min_y
|
||||
|
||||
|
||||
def solve(passes: List[str]) -> int:
|
||||
return max(seat_id(p) for p in passes)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue