Given are 16 equidistant points in a 4x4 grid.
The coordinates are given with with @set = ([0,0],[0,1],...[3,3])
y 3 o o o o <- [3,3] 2 o o o o 1 o o o o 0 o o o o <- [3,0] 0 1 2 3 x
Task: Find a polygon° with 6 edges, crossing each grid-point exactly once.
@polygon = ([x0,y0],...[x6,y6])
Example: the edge ([-1,4],[3,0]) is crossing 4 points.
Hints:
Disclaimer: I didn't code it yet, but I saw existing solutions.
Have fun! :)
PS: Extra points for generalized solutions for bigger grids. While this can be solved with paper and pen, I'm expecting code to solve it.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
Changed orientation of coordinate system to have 0,0 at the left lower corner like in math convention.
°) or rather Polygonal_chain
*) See Coding challenges to PM
|
|---|