Skip to content

Commit

Permalink
day25a
Browse files Browse the repository at this point in the history
  • Loading branch information
onlycs committed Dec 25, 2024
1 parent aa8533c commit 7254f63
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ fn fetch() {
fn main() {
runner!(
day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12, day13,
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24
day14, day15, day16, day17, day18, day19, day20, day21, day22, day23, day24, day25
);
}
6 changes: 0 additions & 6 deletions solutions/src/day08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,10 @@ problem_parser!(ty_parser!(Input));

pub fn level1(mut input: Input) -> usize {
input.antinodify_all();

println!("{input}");

input.count_antinodes()
}

pub fn level2(mut input: Input) -> usize {
input.antinodify_all2();

println!("{input}");

input.count_antinodes()
}
4 changes: 1 addition & 3 deletions solutions/src/day11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ fn solve(data: Input, steps: usize) -> usize {
acc
});

for i in 0..steps {
println!("step {i}");

for _ in 0..steps {
for (num, occurrences) in counts.drain().collect_vec() {
let mut add = |num: u64| {
counts
Expand Down
55 changes: 55 additions & 0 deletions solutions/src/day25.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use itertools::Itertools;
use libadvent::IsInput;

fn parse_bitmap(s: &[&str]) -> u32 {
s.iter()
.flat_map(|line| line.chars())
.fold(0, |acc, ch| acc << 1 | (ch == '#') as u32)
}

pub struct Input {
locks: Vec<u32>,
keys: Vec<u32>,
}

impl IsInput for Input {
fn parse(s: &str) -> Self {
let mut locks = Vec::new();
let mut keys = Vec::new();

for item in s.split("\n\n") {
let lines = item.lines().collect_vec();
let is_key = lines[0].starts_with("#");
let end = lines.len() - 1;
let b = parse_bitmap(&lines[1..end]);

if is_key {
keys.push(b);
} else {
locks.push(b);
}
}

Self { locks, keys }
}
}

problem_parser!(ty Input);

pub fn level1(combos: Input) -> usize {
let mut fit = 0;

for key in &combos.keys {
for lock in &combos.locks {
if key & lock == 0 {
fit += 1;
}
}
}

fit
}

pub fn level2(_: Input) -> String {
"Merry Christmas!".to_string()
}
1 change: 1 addition & 0 deletions solutions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ pub mod day21;
pub mod day22;
pub mod day23;
pub mod day24;
pub mod day25;

0 comments on commit 7254f63

Please sign in to comment.