Skip to content

Instantly share code, notes, and snippets.

@seleb
Created April 22, 2018 01:41
Show Gist options
  • Save seleb/f80fccf7bf3289e89324dc216d8643d1 to your computer and use it in GitHub Desktop.
Save seleb/f80fccf7bf3289e89324dc216d8643d1 to your computer and use it in GitHub Desktop.
All horizontal, vertical, and diagonal paths on a grid
grid=7 --8x8
paths={}
--horizontal
for y=0,grid do
local p={}
for x=0,grid do
add(p,{x=x,y=y})
end
add(paths,p)
end
--vertical
for x=0,grid do
local p={}
for y=0,grid do
add(p,{x=x,y=y})
end
add(paths,p)
end
--diag
for y=-grid,grid do
local p1={}
local p2={}
local p3={}
local p4={}
for a=0,y do
add(p1,{y=y-a,x=a})
add(p2,{y=grid-y+a,x=grid-a})
add(p3,{y=y-a,x=grid-a})
add(p4,{y=grid-y+a,x=a})
end
add(paths,p1)
add(paths,p2)
add(paths,p3)
add(paths,p4)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment