32 lines
737 B
Rust
32 lines
737 B
Rust
|
const INPUT: &str = include_str!("../../data/day5/input");
|
||
|
|
||
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
|
||
|
struct Seat {
|
||
|
id: u16,
|
||
|
}
|
||
|
|
||
|
impl Seat {
|
||
|
fn parse(data: &str) -> Self {
|
||
|
let data = data.trim();
|
||
|
assert_eq!(data.len(), 10);
|
||
|
let id = data.chars().map(|c| c == 'B' || c == 'R').fold(0, |mask, bit| mask * 2 + if bit { 1 } else { 0 });
|
||
|
Self { id }
|
||
|
}
|
||
|
|
||
|
fn parse_list(input: &str) -> Vec<Self> {
|
||
|
input.lines().map(Seat::parse).collect()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let mut seats = Seat::parse_list(INPUT);
|
||
|
println!("Max Seat id: {}", seats.iter().max().unwrap().id);
|
||
|
seats.sort();
|
||
|
for i in 0..seats.len()-1 {
|
||
|
if seats[i].id + 1 != seats[i+1].id {
|
||
|
println!("Empty seat: {}", seats[i].id + 1);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|