Skip to content

Commit

Permalink
-- layers
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed May 25, 2024
1 parent 81b5244 commit ee4d299
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sandbox/src/main/scala/snake/Snake.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ object Snake {
if (y == 0) next + x
else snake(h - 1, w, y - 1, w - x - 1, next + w)

def layers2(w: Int, h: Int, x: Int, y: Int) = {
val layer = x min y min (w - (x + 1)) min (h - (y + 1))

if (layer == y) 2 * layer * (w + h - 2 * layer - 1) + (x - layer + 1) // top triangle with diagonals
else if (layer == w - (x + 1)) 2 * layer * (w + h - 2 * layer - 1) + (w - 2 * layer - 1 + y - layer + 1) // right
else if (layer == h - (y + 1)) 2 * layer * (w + h - 2 * layer - 1) + (w + h - 4 * layer - 3 + w - 1 - layer - x + 1) // bottom
else if (layer == x) 2 * layer * (w + h - 2 * layer - 1) + (2 * (w + h - 4 * layer - 2) + h - 1 - layer - y + 1) // left
else ???
}

def layers(w: Int, h: Int, x: Int, y: Int) = {
val layer = x min y min (w - 1 - x) min (h - 1 - y)
if (y == layer)
Expand Down

0 comments on commit ee4d299

Please sign in to comment.