Skip to content

Instantly share code, notes, and snippets.

@ft975
Created July 16, 2013 21:00
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 ft975/6012608 to your computer and use it in GitHub Desktop.
Save ft975/6012608 to your computer and use it in GitHub Desktop.
def iterateTouching(x: Int, y: Int, z: Int, cond: (Int, Int, Int) => Boolean, op: (Int, Int, Int) => Unit) {
if (cond(x + 1, y, z)) {
op(x + 1, y, z)
iterateTouching(x + 1, y, z, cond, op)
}
if (cond(x - 1, y, z)) {
op(x - 1, y, z)
iterateTouching(x - 1, y, z, cond, op)
}
if (cond(x, y + 1, z)) {
op(x, y + 1, z)
iterateTouching(x, y + 1, z, cond, op)
}
if (cond(x, y - 1, z)) {
op(x, y - 1, z)
iterateTouching(x, y - 1, z, cond, op)
}
if (cond(x, y, z + 1)) {
op(x, y, z + 1)
iterateTouching(x, y, z + 1, cond, op)
}
if (cond(x, y, z - 1)) {
op(x, y, z - 1)
iterateTouching(x, y, z - 1, cond, op)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment