really tight solution to day 5
This commit is contained in:
25
2020/day_5/src/main.rs
Normal file
25
2020/day_5/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
fn main() {
|
||||
let contents = std::fs::read_to_string("input").unwrap();
|
||||
let mut passes = Vec::new();
|
||||
for line in contents.lines() {
|
||||
let code = line
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
'L' | 'F' => '0',
|
||||
'R' | 'B' => '1',
|
||||
_ => c,
|
||||
})
|
||||
.collect::<String>();
|
||||
let code_in_bin = isize::from_str_radix(&code.to_string(), 2).unwrap() as u32;
|
||||
passes.push(code_in_bin);
|
||||
}
|
||||
passes.sort();
|
||||
// println!("{:?}", passes);
|
||||
let min: u32 = passes.first().cloned().unwrap();
|
||||
let max: u32 = passes.last().cloned().unwrap();
|
||||
for i in min..max {
|
||||
if !passes.contains(&i) {
|
||||
println!("Seat {} is empy", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user