70 %

# Advent of Code 2020 in Rust day 5: bitvec

Day 5 was basically binary numbers in disguise.

rust
`#[test]fn test_input_one() {    assert_eq!(process_seat("FBFBBFFRLR"), Seat { row: 44, column: 5 });}`

Turning `FBFBBFFRLR` into the numbers on the right (44 and 5) is as easy as converting them to 1s and 0s.

`FBFBBFF` -> `0101100` -> 32 + 8 + 4 -> 44

`RLR` -> `101` -> 4 + 1 -> 5

The `bitvec` crate allows us to turn an iterator of boolean values into a vector of bits, then load it as a u8.

bitvec.rs
rust
```#[derive(Debug, Eq, PartialEq)]struct Seat {    row: usize,    column: usize,}impl Seat {    fn id(&self) -> usize {        self.row * 8 + self.column    }}
fn process_seat(input: &str) -> Seat {    let mut groups = input        .chars()        .group_by(|c| *c == 'F' || *c == 'B')        .into_iter()        .map(|(_, s)| {            s.map(|v| match v {                'B' | 'R' => true,                'F' | 'L' => false,                _ => panic!("asfkj"),            })            .collect::<BitVec>()        })        .collect::<Vec<_>>();
groups.reverse();    groups.reverse();

We can speed it up a little by dropping the `group_by`.

two_iterators.rs
rust
```fn char_to_bool(c: char) -> bool {    match c {        'B' | 'R' => true,        'F' | 'L' => false,        _ => panic!("asfkj"),    }}
fn process_seat(input: &str) -> Seat {    let mut a = input.chars().take(7).map(char_to_bool).collect::<BitVec>();    let mut b = input        .chars()        .skip(7)        .take(3)        .map(char_to_bool)        .collect::<BitVec>();
a.reverse();    b.reverse();