fn adjacency_map(g: &SimpleGrid) -> (Vec<Place>, Vec<Vec<usize>>) {
    let mut seats = vec![Place::Floor; g.rows() * g.cols()];
    let mut adjacency_map = vec![vec![]; g.rows() * g.cols()];
    for (pos, c) in g.entries_by_location() {
        let i = pos.y as usize * g.cols() + pos.x as usize;
        match c {
            &b'#' => { seats[i] = Place::OccupiedSeat; },
            &b'L' => { seats[i] = Place::EmptySeat; },
            _ => { continue; },
        }
        for d in &DIRECTIONS {
            let dpos = pos.go(d);
            if g.get_by_location(&dpos).filter(|c| **c != b'.').is_some() {
                let di = dpos.y as usize * g.cols() + dpos.x as usize;
                adjacency_map[i].push(di);
            }
        }
    }
    (seats, adjacency_map)
}
// Returns the seats as a vector v together with an adjacency map m:
// v[i] is the state of place i and m[i] is the list of seats adjacent to i.
Returns the seats as a vector v together with an adjacency map m:
v[i] is the state of place i and m[i] is the list of seats adjacent to i.
Returns the seats as a vector v together with an adjacency map m : v [ i ] is the state of place i and m [ i ] is the list of seats adjacent to i .
fn adjacency_map(g: &SimpleGrid) -> (Vec<Place>, Vec<Vec<usize>>) {
    let mut seats = vec![Place::Floor; g.rows() * g.cols()];
    let mut adjacency_map = vec![vec![]; g.rows() * g.cols()];
    for (pos, c) in g.entries_by_location() {
        let i = pos.y as usize * g.cols() + pos.x as usize;
        match c {
            &b'#' => { seats[i] = Place::OccupiedSeat; },
            &b'L' => { seats[i] = Place::EmptySeat; },
            _ => { continue; },
        }
        for d in &DIRECTIONS {
            let dpos = pos.go(d);
            if g.get_by_location(&dpos).filter(|c| **c != b'.').is_some() {
                let di = dpos.y as usize * g.cols() + dpos.x as usize;
                adjacency_map[i].push(di);
            }
        }
    }
    (seats, adjacency_map)
}
fn adjacency_map ( g : & SimpleGrid ) -> ( Vec < Place > , Vec < Vec < usize > > ) { let mut seats = vec ! [ Place Floor g rows ( ) g cols ( ) ] ; let mut adjacency_map = vec ! [ vec [ ] g rows ( ) g cols ( ) ] ; for ( pos , c ) in g . entries_by_location ( ) { let i = pos . y as usize * g . cols ( ) + pos . x as usize ; match c { & b'#' => { seats [ i ] = Place :: OccupiedSeat ; } , & b'L' => { seats [ i ] = Place :: EmptySeat ; } , _ => { continue ; } , } for d in & DIRECTIONS { let dpos = pos . go ( d ) ; if g . get_by_location ( & dpos ) . filter ( | c | * * c != b'.' ) . is_some ( ) { let di = dpos . y as usize * g . cols ( ) + dpos . x as usize ; adjacency_map [ i ] . push ( di ) ; } } } ( seats , adjacency_map ) }
Returns the seats as a vector v together with an adjacency map m:
v[i] is the state of place i and m[i] is the list of seats adjacent to i.
Returns the seats as a vector v together with an adjacency map m : v [ i ] is the state of place i and m [ i ] is the list of seats adjacent to i .
g
&SimpleGrid