part1 (2930B)
1--- Day 5: Binary Boarding --- 2 3You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure 4which seat is yours, and all of the flight attendants are busy with the flood of people that 5suddenly made it through passport control. 6 7You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your 8puzzle input); perhaps you can find your seat through process of elimination. 9 10Instead of zones or groups, this airline uses [1m[37mbinary space partitioning[0m to seat people. 11A seat might be specified like FBFBBFFRLR, where F means "front", B means "back", L means "left", 12and R means "right". 13 14The first 7 characters will either be F or B; these specify exactly one of the [1m[37m128 rows[0m 15on the plane (numbered 0 through 127). Each letter tells you which half of a region the given seat 16is in. Start with the whole list of rows; the first letter indicates whether the seat is in the 17[1m[37mfront[0m (0 through 63) or the [1m[37mback[0m (64 through 127). The next letter 18indicates which half of that region the seat is in, and so on until you're left with exactly one 19row. 20 21For example, consider just the first seven characters of FBFBBFFRLR: 22 23- Start by considering the whole range, rows 0 through 127. - F means to take the [1m[37mlower 24half[0m, keeping rows 0 through 63. - B means to take the [1m[37mupper half[0m, keeping rows 32 25through 63. - F means to take the [1m[37mlower half[0m, keeping rows 32 through 47. - B means to 26take the [1m[37mupper half[0m, keeping rows 40 through 47. - B keeps rows 44 through 47. - F 27keeps rows 44 through 45. - The final F keeps the lower of the two, [1m[37mrow 44[0m. 28 29The last three characters will be either L or R; these specify exactly one of the [1m[37m8 30columns[0m of seats on the plane (numbered 0 through 7). The same process as above proceeds again, 31this time with only three steps. L means to keep the [1m[37mlower half[0m, while R means to keep 32the [1m[37mupper half[0m. 33 34For example, consider just the last 3 characters of FBFBBFFRLR: 35 36- Start by considering the whole range, columns 0 through 7. - R means to take the [1m[37mupper 37half[0m, keeping columns 4 through 7. - L means to take the [1m[37mlower half[0m, keeping 38columns 4 through 5. - The final R keeps the upper of the two, [1m[37mcolumn 5[0m. 39 40So, decoding FBFBBFFRLR reveals that it is the seat at [1m[37mrow 44, column 5[0m. 41 42Every seat also has a unique [1m[37mseat ID[0m: multiply the row by 8, then add the column. In 43this example, the seat has ID 44 * 8 + 5 = [1m[37m357[0m. 44 45Here are some other boarding passes: 46 47- BFFFBBFRRR: row 70, column 7, seat ID 567. - FFFBBBFRRR: row 14, column 7, seat ID 119. - 48BBFFBBFRLL: row 102, column 4, seat ID 820. 49 50As a sanity check, look through your list of boarding passes. [1m[37mWhat is the highest seat ID 51on a boarding pass?[0m 52 53