pub fn layout(grid: &mut Grid, wire: &str) {
    let operations = wire.split(",");
    let mut visited: Vec<Point> = Vec::new();
    let mut curr_x: i32 = 0;
    let mut curr_y: i32 = 0;
    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"),
            }
            visited.push((curr_x, curr_y));
        }
    }
    // We need to sort this and remove duplicate visited `Point`s,
    // so that we don't count a wire crossing itself twice.
    visited.sort();
    visited.dedup();
    for point in visited {
        let spot = grid.entry(point).or_insert(0);
        *spot += 1;
    }
}
/// Lays out a wire on the grid, starting at (0,0) following the order of operations for the wire
/// Does not count a wire crossing itself twice
Lays out a wire on the grid, starting at (0,0) following the order of operations for the wire
Does not count a wire crossing itself twice
Lays out a wire on the grid starting at ( 0 0 ) following the order of operations for the wire Does not count a wire crossing itself twice
pub fn layout(grid: &mut Grid, wire: &str) {
    let operations = wire.split(",");
    let mut visited: Vec<Point> = Vec::new();
    let mut curr_x: i32 = 0;
    let mut curr_y: i32 = 0;
    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"),
            }
            visited.push((curr_x, curr_y));
        }
    }
    // We need to sort this and remove duplicate visited `Point`s,
    // so that we don't count a wire crossing itself twice.
    visited.sort();
    visited.dedup();
    for point in visited {
        let spot = grid.entry(point).or_insert(0);
        *spot += 1;
    }
}
pub fn layout ( grid : & mut Grid , wire : & str ) { let operations = wire . split ( " " ) ; let mut visited : Vec < Point > = Vec :: new ( ) ; let mut curr_x : i32 = 0 ; let mut curr_y : i32 = 0 ; 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 ! ( " " ) , } visited . push ( ( curr_x , curr_y ) ) ; } } // We need to sort this and remove duplicate visited `Point`s, // so that we don't count a wire crossing itself twice. visited . sort ( ) ; visited . dedup ( ) ; for point in visited { let spot = grid . entry ( point ) . or_insert ( 0 ) ; * spot += 1 ; } }
Lays out a wire on the grid, starting at (0,0) following the order of operations for the wire
Does not count a wire crossing itself twice
Lays out a wire on the grid starting at ( 0 0 ) following the order of operations for the wire Does not count a wire crossing itself twice
grid
&mut Grid
wire
&str
grid
&mut Grid
wire
&str