tidy logic
This commit is contained in:
parent
eb89350ddf
commit
49fcba6c4a
1 changed files with 4 additions and 6 deletions
|
@ -127,8 +127,6 @@ impl Board {
|
|||
fn antinodes(&self, a1: Loc, a2: Loc) -> Vec<Loc> {
|
||||
let dy = (a1.0 as i64 - a2.0 as i64).unsigned_abs() as usize;
|
||||
let dx = (a1.1 as i64 - a2.1 as i64).unsigned_abs() as usize;
|
||||
let mut n1: Loc;
|
||||
let mut n2: Loc;
|
||||
// row 0 is at the top
|
||||
let (top, bottom) = if a1.0 <= a2.0 { (a1, a2) } else { (a2, a1) };
|
||||
let (left, right) = if a1.1 <= a2.1 { (a1, a2) } else { (a2, a1) };
|
||||
|
@ -140,9 +138,9 @@ impl Board {
|
|||
let nx_right = right.1 + dx;
|
||||
|
||||
let (n1, n2) = match (a1, a2) {
|
||||
_ if a1 == top && a1 == left => (Loc(ny_top, nx_left), Loc(ny_bot, nx_right)),
|
||||
_ if a1 == top && a1 == right => (Loc(ny_top, nx_right), Loc(ny_bot, nx_left)),
|
||||
_ if a1 == bottom && a1 == left => (Loc(ny_bot, nx_left), Loc(ny_top, nx_right)),
|
||||
_ if top == left => (Loc(ny_top, nx_left), Loc(ny_bot, nx_right)),
|
||||
_ if top == right => (Loc(ny_top, nx_right), Loc(ny_bot, nx_left)),
|
||||
_ if bottom == left => (Loc(ny_bot, nx_left), Loc(ny_top, nx_right)),
|
||||
_ => (Loc(ny_bot, nx_right), Loc(ny_top, nx_left)),
|
||||
};
|
||||
|
||||
|
@ -203,6 +201,6 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn p2() {
|
||||
assert_eq!(6, pt2(INPUT));
|
||||
assert_eq!(34, pt2(INPUT));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue