Day 5: Binary Boarding¶
Functions:
|
Apply the |
|
Compute the row of the seat identified by the |
|
Compute the column of the seat identified by the |
|
Compute the |
|
Compute the identifier of the seat given its |
- apply(first: int, last: int, directive: str) Tuple[int, int] [source]¶
Apply the
directive
given the range as[first, last]
(inclusive).- Returns
new first, new last
- Requires
re.match(r"^[FBLR]Z", directive)
first >= 0
last >= 1
first % 2 == 0
last % 2 == 1
first < last
(last - first + 1) % 2 == 0
(Range always divisible by 2)
- Ensures
result[0] != result[1]
⇒result[1] % 2 == 1
(next last always not divisible by 2 unless the last step)
result[0] != result[1]
⇒result[0] % 2 == 0
(next first always divisible by 2 unless the last step)
first <= result[0] <= result[1] <= last
not (directive in "BR") or (first < result[0] and result[1] == last)
(Only first increases on B/R.)
not (directive in "FL") or (result[0] == first and result[1] < last)
(Only last decreases on F/L.)
- determine_row(identifier: str) int [source]¶
Compute the row of the seat identified by the
identifier
.- Requires
re.match(r"^[FB]{7}Z", identifier)
- Ensures
0 <= result <= 127
- determine_column(identifier: str) int [source]¶
Compute the column of the seat identified by the
identifier
.- Requires
re.match(r"^[LR]{3}Z", identifier)
- Ensures
0 <= result <= 127