condense day 12 by combining pattern match arms

Signed-off-by: Stephen Waits <swaits@amazon.com>
This commit is contained in:
Stephen Waits committed 2020-12-12 06:22:43 -08:00
1 parent 9269a60cde
commit 16670f26a5
1 file changed
+4 -19
+4 -19
View File
@@ -45,34 +45,19 @@ fn navigate2(data: &str) -> usize {
"S" => wpt_n -= dist,
"E" => wpt_e += dist,
"W" => wpt_e -= dist,
"L" => match dist {
270 => {
wpt_e = -wpt_e;
mem::swap(&mut wpt_n, &mut wpt_e);
}
180 => {
wpt_n = -wpt_n;
wpt_e = -wpt_e;
}
90 => {
"L" | "R" => match (dir, dist) {
("L", 90) | ("R", 270) => {
wpt_n = -wpt_n;
mem::swap(&mut wpt_n, &mut wpt_e);
}
_ => panic!("bad direction!"),
},
"R" => match dist {
90 => {
("L", 270) | ("R", 90) => {
wpt_e = -wpt_e;
mem::swap(&mut wpt_n, &mut wpt_e);
}
180 => {
(_, 180) => {
wpt_n = -wpt_n;
wpt_e = -wpt_e;
}
270 => {
wpt_n = -wpt_n;
mem::swap(&mut wpt_n, &mut wpt_e);
}
_ => panic!("bad direction!"),
},
"F" => {