Added Day 6 Part 1
This commit is contained in:
parent
1797dd8b3d
commit
c2309defe8
19
small.input
19
small.input
|
@ -1,4 +1,15 @@
|
|||
FBFBBFFRLR
|
||||
BFFFBBFRRR
|
||||
FFFBBBFRRR
|
||||
BBFFBBFRLL
|
||||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -1,37 +1,25 @@
|
|||
use std::collections::HashSet;
|
||||
use std::io::{stdin, Read};
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
stdin().read_to_string(&mut input).unwrap();
|
||||
|
||||
let filled_seats = input
|
||||
.split('\n')
|
||||
let questions = input
|
||||
.split("\n\n")
|
||||
.filter(|x| !x.is_empty())
|
||||
.into_iter()
|
||||
.map(|seat| {
|
||||
let seat = seat.chars();
|
||||
let mut region: u16 = 0;
|
||||
.map(|set| {
|
||||
let mut q = [false; 26];
|
||||
|
||||
for s in seat {
|
||||
region <<= 1;
|
||||
region |= match s {
|
||||
'B' | 'R' => 1,
|
||||
'F' | 'L' | _ => 0,
|
||||
};
|
||||
}
|
||||
set.chars()
|
||||
.filter(|&x| char::is_alphabetic(x))
|
||||
.for_each(|y| {
|
||||
q[(y as u8 - 97) as usize] = true;
|
||||
});
|
||||
|
||||
(region >> 3) * 8 + (region & 0b111)
|
||||
q.iter().fold(0, |a, &x| if x { a + 1 } else { a })
|
||||
})
|
||||
.collect::<HashSet<u16>>();
|
||||
.sum::<i32>();
|
||||
|
||||
let min = *filled_seats.iter().min().unwrap();
|
||||
let max = *filled_seats.iter().max().unwrap();
|
||||
|
||||
for i in min..max {
|
||||
if !filled_seats.contains(&i) {
|
||||
println!("seat = {}", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
println!("questions = {:?}", questions);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user