Skip to content

Instantly share code, notes, and snippets.

@sherjilozair
Created December 11, 2021 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sherjilozair/11bc196cc79b43f7f724f9925ea84fb7 to your computer and use it in GitHub Desktop.
Save sherjilozair/11bc196cc79b43f7f724f9925ea84fb7 to your computer and use it in GitHub Desktop.
// 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