condense day 12 by combining pattern match arms
Signed-off-by: Stephen Waits <swaits@amazon.com>
This commit is contained in:
1 file changed
+4
-19
+4
-19
@@ -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" => {
|
||||
|
||||
Reference in new issue
Block a user