This commit is contained in:
kageru 2023-12-18 17:08:53 +01:00
parent 2d506e3799
commit 28fe5655b2
2 changed files with 4 additions and 4 deletions

View File

@ -11,7 +11,7 @@ fn parse_input(raw: &str) -> Parsed {
}
fn hash(s: &[u8]) -> I {
s.iter().fold(0, |acc, &b| (acc + b as I) * 17 & 255)
s.iter().fold(0, |acc, &b| ((acc + b as I) * 17) & 255)
}
fn part1(parsed: &Parsed) -> I {
@ -23,13 +23,13 @@ fn part2(parsed: &Parsed) -> I {
for s in parsed.clone() {
match s.as_bytes() {
[label @ .., b'-'] => {
let hash = hash(&label);
let hash = hash(label);
if let Some(p) = boxes[hash].iter().position(|(l, _)| l == &label) {
boxes[hash].remove(p);
}
}
[label @ .., b'=', focal_strength] => {
let hash = hash(&label);
let hash = hash(label);
match boxes[hash].iter().position(|(l, _)| l == &label) {
Some(p) => boxes[hash][p] = (&label, focal_strength - b'0'),
None => boxes[hash].push((&label, focal_strength - b'0')),

View File

@ -35,7 +35,7 @@ impl<I: Inc + Add<I, Output = I> + AddAssign + Debug, const DIMS: usize> Positio
let ns = neighbor_vectors::<I, DIMS>();
let mut out = [*self; num_neighbors(DIMS)];
for (out, dir) in out.iter_mut().zip(IntoIterator::into_iter(ns).filter(|n| n != &[I::default(); DIMS])) {
*out = *out + PositionND(dir);
*out += PositionND(dir);
}
out
}