1
0
Fork 0

Added Day 11 Part 2

This commit is contained in:
Ishan Jain 2021-12-11 11:25:34 +05:30
parent 78b4b9e82d
commit a608a6ad07
1 changed files with 5 additions and 11 deletions

View File

@ -14,12 +14,11 @@ fn parse_input(input: &'static str) -> Vec<Vec<u64>> {
} }
fn solution(mut input: Vec<Vec<u64>>) -> u64 { fn solution(mut input: Vec<Vec<u64>>) -> u64 {
let mut flashes = 0;
let m = input.len(); let m = input.len();
let n = input[0].len(); let n = input[0].len();
let mut step = 1;
for _ in 1..=100 { loop {
for row in input.iter_mut() { for row in input.iter_mut() {
for col in row { for col in row {
if *col == 9 { if *col == 9 {
@ -41,16 +40,11 @@ fn solution(mut input: Vec<Vec<u64>>) -> u64 {
} }
input = tmp; input = tmp;
for row in input.iter() { if input.iter().all(|row| row.iter().all(|&c| c == 0)) {
for &col in row { return step;
if col == 0 {
flashes += 1;
}
}
} }
step += 1;
} }
flashes
} }
fn dfs(ip: &mut Vec<Vec<u64>>, i: i32, j: i32) { fn dfs(ip: &mut Vec<Vec<u64>>, i: i32, j: i32) {