Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- Point = tuple
- x,y: int
- proc Neighbors(pos:Point):seq[Point]
- var point:Point = (x:3, y:3)
- for pos in point.Neighbors():
- echo $pos
- proc Neighbors(pos:Point):seq[Point] =
- result = @[]
- for offset in @[(0,-1),(0,1),(-1,0),(1,0)]:
- var newPos = pos
- newPos.x = newPos.x + offset[0]
- newPos.y = newPos.y + offset[1]
- result.add(newPos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement