diff --git a/src/main.rs b/src/main.rs index 01e8c35..7d36a4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,13 +8,17 @@ mod rover { type Rover = (i32, i32, Facing); - pub fn forward((lon, lat, direction) : Rover) -> Rover { - let (xoff, yoff) = match direction { + fn velocity(direction : &Facing) -> (i32, i32) { + match direction { Facing::N => ( 0, -1), Facing::E => ( 1, 0), Facing::S => ( 0, 1), Facing::W => (-1, 0) - }; + } + } + + pub fn forward((lon, lat, direction) : Rover) -> Rover { + let (xoff, yoff) = velocity(&direction); (lon + xoff as i32, lat + yoff as i32, direction) } }