rust(day06): yee
This commit is contained in:
parent
a44bc3ea57
commit
a4dda171b5
|
@ -0,0 +1,41 @@
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
fn count_bits(i: u32) -> u32 {
|
||||||
|
let i = i - ((i >> 1) & 0x55555555);
|
||||||
|
let i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
|
||||||
|
(((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(print: bool) -> Duration {
|
||||||
|
let file_string = std::fs::read_to_string("../inputs/06").unwrap();
|
||||||
|
let instant = Instant::now();
|
||||||
|
|
||||||
|
let mut part1 = 0;
|
||||||
|
let mut part2 = 0;
|
||||||
|
|
||||||
|
for group in file_string.trim().split("\n\n") {
|
||||||
|
let mut set = 0u32;
|
||||||
|
for c in group.chars().filter(|c| c.is_alphabetic()) {
|
||||||
|
set |= 1 << (c as usize - 'a' as usize);
|
||||||
|
}
|
||||||
|
part1 += count_bits(set);
|
||||||
|
|
||||||
|
let mut line_set = 0u32;
|
||||||
|
for c in group.chars() {
|
||||||
|
if c == '\n' {
|
||||||
|
set &= line_set;
|
||||||
|
line_set = 0;
|
||||||
|
} else {
|
||||||
|
line_set |= 1 << (c as usize - 'a' as usize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set &= line_set;
|
||||||
|
part2 += count_bits(set);
|
||||||
|
}
|
||||||
|
|
||||||
|
if print {
|
||||||
|
dbg!(part1, part2);
|
||||||
|
}
|
||||||
|
|
||||||
|
instant.elapsed()
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ mod day02;
|
||||||
mod day03;
|
mod day03;
|
||||||
mod day04;
|
mod day04;
|
||||||
mod day05;
|
mod day05;
|
||||||
use nop as day06;
|
mod day06;
|
||||||
use nop as day07;
|
use nop as day07;
|
||||||
mod day08;
|
mod day08;
|
||||||
mod day09;
|
mod day09;
|
||||||
|
|
Loading…
Reference in New Issue