Added hashbrown

This commit is contained in:
Jan-Bulthuis committed 2024-12-08 14:54:14 +01:00
1 parent 6e0519aa27
commit b522357495
3 files changed
+38 -14

No files matched your search

+7 -14
View File
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use hashbrown::{HashMap, HashSet};
use aoc_runner_derive::{aoc, aoc_generator};
use num::integer::gcd;
@@ -15,11 +15,9 @@ fn parse(input: &str) -> Input {
.enumerate()
.filter(|(_, c)| c != &'.')
.for_each(|(x, c)| {
if let std::collections::hash_map::Entry::Vacant(e) = map.entry(c) {
e.insert(vec![(x as isize, y as isize)]);
} else {
map.get_mut(&c).unwrap().push((x as isize, y as isize));
}
map.entry(c)
.or_insert(Vec::new())
.push((x as isize, y as isize));
});
});
let vec = map.into_values().collect();
@@ -28,7 +26,7 @@ fn parse(input: &str) -> Input {
#[aoc(day8, part1)]
fn part1(input: &Input) -> usize {
let mut set = HashSet::with_capacity(input.1.len() * input.1.len());
let mut set = HashSet::new();
input.1.iter().for_each(|vec| {
for l in 0..vec.len() {
for r in l + 1..vec.len() {
@@ -58,7 +56,6 @@ fn part2(input: &Input) -> usize {
let a2 = vec[r];
let s = a1;
let v = (a2.0 - a1.0, a2.1 - a1.1);
let v = (v.0 / gcd(v.0, v.1), v.1 / gcd(v.0, v.1));
let mut d = 0;
loop {
let c = (s.0 + d * v.0, s.1 + d * v.1);
@@ -82,12 +79,6 @@ fn part2(input: &Input) -> usize {
}
}
});
// for y in 0..input.0 .1 {
// println!();
// for x in 0..input.0 .0 {
// print!("{}", if set.contains(&(x, y)) { '#' } else { '.' })
// }
// }
set.len()
}
@@ -113,5 +104,7 @@ mod tests {
)),
34
);
assert_eq!(part2(&parse(include_str!("../input/2024/day8.txt"))), 1017);
}
}