Skip to content

Instantly share code, notes, and snippets.

@sherjilozair
Created December 11, 2021 16:05
Show Gist options
  • Save sherjilozair/a3b765edb51c5d560e05c7277393c095 to your computer and use it in GitHub Desktop.
Save sherjilozair/a3b765edb51c5d560e05c7277393c095 to your computer and use it in GitHub Desktop.
// check if any greater than 9, set them to -1
// and increase neighboring and diagonal numbers
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] += 1;
}
if i < input.len() - 1 {
input[i + 1][j] += 1;
}
if j > 0 {
input[i][j - 1] += 1;
}
if j < input[i].len() - 1 {
input[i][j + 1] += 1;
}
if i > 0 && j > 0 {
input[i - 1][j - 1] += 1;
}
if i > 0 && j < input[i].len() - 1 {
input[i - 1][j + 1] += 1;
}
if i < input.len() - 1 && j > 0 {
input[i + 1][j - 1] += 1;
}
if i < input.len() - 1 && j < input[i].len() - 1 {
input[i + 1][j + 1] += 1;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment