1
0
Fork 0

Added Day 6 Part 1

This commit is contained in:
Ishan Jain 2020-12-06 10:40:31 +05:30
parent 1797dd8b3d
commit c2309defe8
No known key found for this signature in database
GPG Key ID: F261A0E73038D89D
3 changed files with 2226 additions and 895 deletions

3066
input

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,37 +1,25 @@
use std::collections::HashSet;
use std::io::{stdin, Read}; use std::io::{stdin, Read};
fn main() { fn main() {
let mut input = String::new(); let mut input = String::new();
stdin().read_to_string(&mut input).unwrap(); stdin().read_to_string(&mut input).unwrap();
let filled_seats = input let questions = input
.split('\n') .split("\n\n")
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.into_iter() .into_iter()
.map(|seat| { .map(|set| {
let seat = seat.chars(); let mut q = [false; 26];
let mut region: u16 = 0;
for s in seat { set.chars()
region <<= 1; .filter(|&x| char::is_alphabetic(x))
region |= match s { .for_each(|y| {
'B' | 'R' => 1, q[(y as u8 - 97) as usize] = true;
'F' | 'L' | _ => 0, });
};
}
(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(); println!("questions = {:?}", questions);
let max = *filled_seats.iter().max().unwrap();
for i in min..max {
if !filled_seats.contains(&i) {
println!("seat = {}", i);
break;
}
}
} }