Created
December 11, 2021 16:40
-
-
Save sherjilozair/11bc196cc79b43f7f724f9925ea84fb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// check if any greater than 9, set them to -1 | |
// and call update on valid neighbours and diagonals | |
for i in 0..input.len() { | |
for j in 0..input[i].len() { | |
if input[i][j] > 9 { | |
input[i][j] = -1; | |
if i > 0 { | |
input[i - 1][j] = update(input[i - 1][j]); | |
} | |
if i < input.len() - 1 { | |
input[i + 1][j] = update(input[i + 1][j]); | |
} | |
if j > 0 { | |
input[i][j - 1] = update(input[i][j - 1]); | |
} | |
if j < input[i].len() - 1 { | |
input[i][j + 1] = update(input[i][j + 1]); | |
} | |
if i > 0 && j > 0 { | |
input[i - 1][j - 1] = update(input[i - 1][j - 1]); | |
} | |
if i > 0 && j < input[i].len() - 1 { | |
input[i - 1][j + 1] = update(input[i - 1][j + 1]); | |
} | |
if i < input.len() - 1 && j > 0 { | |
input[i + 1][j - 1] = update(input[i + 1][j - 1]); | |
} | |
if i < input.len() - 1 && j < input[i].len() - 1 { | |
input[i + 1][j + 1] = update(input[i + 1][j + 1]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment