-
Notifications
You must be signed in to change notification settings - Fork 1
/
day05.Rmd
56 lines (44 loc) · 1.82 KB
/
day05.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "--- Day 5: Binary Boarding ---"
author: Fleur Kelpin
date: Dec 5, 2020
output: github_document
---
```{r message=FALSE, warning=FALSE}
library(tidyverse)
input <- read_lines("day05.txt")
as_tibble(input)
```
# Part 1
The first 7 characters will either be F or B; these specify exactly one of the
128 rows on the plane (numbered 0 through 127). Each letter tells you which half
of a region the given seat is in. Start with the whole list of rows; the first
letter indicates whether the seat is in the front (0 through 63) or the back (64
through 127). The next letter indicates which half of that region the seat is
in, and so on until you're left with exactly one row.
The last three characters will be either L or R; these specify exactly one of
the 8 columns of seats on the plane (numbered 0 through 7). The same process as
above proceeds again, this time with only three steps. L means to keep the lower
half, while R means to keep the upper half.
Every seat also has a unique seat ID: multiply the row by 8, then add the
column. In this example, the seat has ID 44 * 8 + 5 = 357.
As a sanity check, look through your list of boarding passes. What is the
highest seat ID on a boarding pass?
```{r}
seats <- input %>%
str_replace_all(c("[BR]" = "1", "[FL]" = "0")) %>%
strtoi(2)
max(seats)
```
# Part 2
Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
It's a completely full flight, so your seat should be the only missing boarding
pass in your list. However, there's a catch: some of the seats at the very front
and back of the plane don't exist on this aircraft, so they'll be missing from
your list as well.
Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1
from yours will be in your list.
What is the ID of your seat?
```{r}
setdiff(min(seats):max(seats), seats)
```