You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
731 B

const INPUT: &str = include_str!("../../data/day5");
#[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;
}
}
}