fn octopus_flashes(octopus_energies: &mut Vec<Vec<u32>>) -> u32 {
    let mut flashed: HashSet<Point> = HashSet::new();
    let mut flashes = VecDeque::new();
    let mut flash_count = 0;

    for x in 0..octopus_energies.len() {
        for y in 0..octopus_energies[x].len() {
            octopus_energies[x][y] += 1;
        }
    }

    for x in 0..octopus_energies.len() {
        for y in 0..octopus_energies[x].len() {
            flashes.push_back((x, y));

            while !flashes.is_empty() {
                if let Some((i, j)) = flashes.pop_front() {
                    let octopus = octopus_energies[i][j];
                    if octopus > 9 && !flashed.contains(&(i, j)) {
                        flashed.insert((i, j));
                        flash_count += 1;

                        for neighbor in get_neighbors(
                            &(i, j),
                            octopus_energies.len(),
                            octopus_energies[x].len(),
                        ) {
                            octopus_energies[neighbor.0][neighbor.1] += 1;
                            flashes.push_back(neighbor);
                        }
                    }
                }
            }
        }
    }

    for flash in flashed {
        octopus_energies[flash.0][flash.1] = 0;
    }

    flash_count
}
/// 1. Each octopus energy increases by 1.
/// 1. Each octopus energy greater than 9 flashes.
/// 1. All adjacent octopus get 1 energy from flashing
/// 1. Octupus can flash at most once
/// 1. Octupus that flash return to 0
1. Each octopus energy increases by 1.
1. Each octopus energy greater than 9 flashes.
1. All adjacent octopus get 1 energy from flashing
1. Octupus can flash at most once
1. Octupus that flash return to 0
1 . Each octopus energy increases by 1 . 1 . Each octopus energy greater than 9 flashes . 1 . All adjacent octopus get 1 energy from flashing 1 . Octupus can flash at most once 1 . Octupus that flash return to 0
fn octopus_flashes(octopus_energies: &mut Vec<Vec<u32>>) -> u32 {
    let mut flashed: HashSet<Point> = HashSet::new();
    let mut flashes = VecDeque::new();
    let mut flash_count = 0;
    for x in 0..octopus_energies.len() {
        for y in 0..octopus_energies[x].len() {
            octopus_energies[x][y] += 1;
        }
    }
    for x in 0..octopus_energies.len() {
        for y in 0..octopus_energies[x].len() {
            flashes.push_back((x, y));
            while !flashes.is_empty() {
                if let Some((i, j)) = flashes.pop_front() {
                    let octopus = octopus_energies[i][j];
                    if octopus > 9 && !flashed.contains(&(i, j)) {
                        flashed.insert((i, j));
                        flash_count += 1;
                        for neighbor in get_neighbors(
                            &(i, j),
                            octopus_energies.len(),
                            octopus_energies[x].len(),
                        ) {
                            octopus_energies[neighbor.0][neighbor.1] += 1;
                            flashes.push_back(neighbor);
                        }
                    }
                }
            }
        }
    }
    for flash in flashed {
        octopus_energies[flash.0][flash.1] = 0;
    }
    flash_count
}
fn octopus_flashes ( octopus_energies : & mut Vec < Vec < u32 > > ) -> u32 { let mut flashed : HashSet < Point > = HashSet :: new ( ) ; let mut flashes = VecDeque :: new ( ) ; let mut flash_count = 0 ; for x in 0 .. octopus_energies . len ( ) { for y in 0 .. octopus_energies [ x ] . len ( ) { octopus_energies [ x ] [ y ] += 1 ; } } for x in 0 .. octopus_energies . len ( ) { for y in 0 .. octopus_energies [ x ] . len ( ) { flashes . push_back ( ( x , y ) ) ; while ! flashes . is_empty ( ) { if let Some ( ( i , j ) ) = flashes . pop_front ( ) { let octopus = octopus_energies [ i ] [ j ] ; if octopus > 9 && ! flashed . contains ( & ( i , j ) ) { flashed . insert ( ( i , j ) ) ; flash_count += 1 ; for neighbor in get_neighbors ( & ( i , j ) , octopus_energies . len ( ) , octopus_energies [ x ] . len ( ) , ) { octopus_energies [ neighbor . 0 ] [ neighbor . 1 ] += 1 ; flashes . push_back ( neighbor ) ; } } } } } } for flash in flashed { octopus_energies [ flash . 0 ] [ flash . 1 ] = 0 ; } flash_count }
1.
1 .
octopus_energies
&mut Vec<Vec<u32>>