clean up part1 helper fn

This commit is contained in:
Joe Ardent 2022-12-09 16:01:08 -08:00
parent 92b6b86197
commit ca854d2cd3

View file

@ -49,16 +49,9 @@ fn new_tail(head: &Position, tail: &Position) -> Position {
let dy = head.1 - tail.1;
let dx = head.0 - tail.0;
match (dx, dy) {
(0, 0) => *tail,
(n, m) if (n.abs() == 1) && (m.abs() == 1) => *tail,
(n, 0) | (0, n) if n.abs() == 1 => *tail,
(_, 2) | (_, -2) if dx.abs() == 1 => (tail.0 + dx, tail.1 + (dy / 2)),
(2, y) | (-2, y) if y.abs() == 1 => {
let sign = dx / dx.abs();
(tail.0 + sign * (dx.abs() - 1), tail.1 + dy)
}
(n, _) if n.abs() == 2 => (tail.0 + n / 2, tail.1),
(_, n) if n.abs() == 2 => (tail.0, tail.1 + n / 2),
_ => unreachable!("got {:?}", (dx, dy)),
(m, n) if m.abs() < 2 && n.abs() < 2 => *tail,
(m, _) if m.abs() == 2 => (tail.0 + m / 2, tail.1 + dy),
(_, m) if m.abs() == 2 => (tail.0 + dx, tail.1 + m / 2),
_ => unreachable!(),
}
}