pub fn layout_with_distance(wire: &str) -> Grid {
    let mut grid = Grid::new();
    let mut distance: u32 = 0;
    let mut curr_x: i32 = 0;
    let mut curr_y: i32 = 0;

    let operations = wire.split(",");
    for operation in operations {
        let dir = &operation[0..1];
        let steps = operation[1..].parse::<usize>().unwrap();
        for _ in 0..steps {
            match dir {
                "U" => curr_y += 1,
                "D" => curr_y -= 1,
                "L" => curr_x -= 1,
                "R" => curr_x += 1,
                _ => panic!("Invalid direction given"),
            }
            distance += 1;
            // Insert the distance travelled so far if we haven't yet hit this `Point`
            grid.entry((curr_x, curr_y)).or_insert(distance);
        }
    }
    grid
}
/// Lay out a wire, starting at (0,0) following the order of operations for the wire
/// Returns the grid of this with the amount of steps needed to reach each particular 'Point`
Lay out a wire, starting at (0,0) following the order of operations for the wire
Returns the grid of this with the amount of steps needed to reach each particular 'Point`
Lay out a wire starting at ( 0 0 ) following the order of operations for the wire Returns the grid of this with the amount of steps needed to reach each particular ' Point `
pub fn layout_with_distance(wire: &str) -> Grid {
    let mut grid = Grid::new();
    let mut distance: u32 = 0;
    let mut curr_x: i32 = 0;
    let mut curr_y: i32 = 0;
    let operations = wire.split(",");
    for operation in operations {
        let dir = &operation[0..1];
        let steps = operation[1..].parse::<usize>().unwrap();
        for _ in 0..steps {
            match dir {
                "U" => curr_y += 1,
                "D" => curr_y -= 1,
                "L" => curr_x -= 1,
                "R" => curr_x += 1,
                _ => panic!("Invalid direction given"),
            }
            distance += 1;
            // Insert the distance travelled so far if we haven't yet hit this `Point`
            grid.entry((curr_x, curr_y)).or_insert(distance);
        }
    }
    grid
}
pub fn layout_with_distance ( wire : & str ) -> Grid { let mut grid = Grid :: new ( ) ; let mut distance : u32 = 0 ; let mut curr_x : i32 = 0 ; let mut curr_y : i32 = 0 ; let operations = wire . split ( " " ) ; for operation in operations { let dir = & operation [ 0 .. 1 ] ; let steps = operation [ 1 .. ] . parse :: < usize > ( ) . unwrap ( ) ; for _ in 0 .. steps { match dir { " " => curr_y += 1 , " " => curr_y -= 1 , " " => curr_x -= 1 , " " => curr_x += 1 , _ => panic ! ( " " ) , } distance += 1 ; // Insert the distance travelled so far if we haven't yet hit this `Point` grid . entry ( ( curr_x , curr_y ) ) . or_insert ( distance ) ; } } grid }
Lay out a wire, starting at (0,0) following the order of operations for the wire
Returns the grid of this with the amount of steps needed to reach each particular 'Point`
Lay out a wire starting at ( 0 0 ) following the order of operations for the wire Returns the grid of this with the amount of steps needed to reach each particular ' Point `
wire
&str
wire
&str