2022 day9/rust: rename some items for clarity

This commit is contained in:
Xiretza 2022-12-09 16:19:29 +01:00
parent d627f1d00f
commit e1862bdcbb

View file

@ -7,8 +7,8 @@ use std::{
use aoc::vec2::{Direction, Vec2}; use aoc::vec2::{Direction, Vec2};
fn tail_movement(following: Vec2, tail: Vec2) -> Vec2 { fn knot_movement(previous: Vec2, knot: Vec2) -> Vec2 {
let (dx, dy) = (following - tail).into(); let (dx, dy) = (previous - knot).into();
let movement = if dx.abs() <= 1 && dy.abs() <= 1 { let movement = if dx.abs() <= 1 && dy.abs() <= 1 {
(0, 0) (0, 0)
@ -33,8 +33,8 @@ fn simulate_knots(num_knots: usize, instructions: &[(Direction, usize)]) -> usiz
let tail = knots let tail = knots
.iter_mut() .iter_mut()
.reduce(|following, knot| { .reduce(|previous, knot| {
*knot += tail_movement(*following, *knot); *knot += knot_movement(*previous, *knot);
knot knot
}) })
.unwrap(); .unwrap();