1
0
Fork 0

Added Day 6 Part 1

master
Ishan Jain 2 years ago
parent 1797dd8b3d
commit c2309defe8
No known key found for this signature in database
GPG Key ID: F261A0E73038D89D

3066
input

File diff suppressed because it is too large Load Diff

@ -1,4 +1,15 @@
FBFBBFFRLR
BFFFBBFRRR
FFFBBBFRRR
BBFFBBFRLL
abc
a
b
c
ab
ac
a
a
a
a
b

@ -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…
Cancel
Save