There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
T Shaw wrote:so I'm a little shaky on how to go about this.
Recursion? Why?Ultimately I want to deploy this to a recursive function that will fill in an individual array for a great deal of the X and Y values in the first two dimensions of the array...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Lq McDonald Iii wrote:Why not just do:
Winston Gutkowski wrote:
T Shaw wrote:so I'm a little shaky on how to go about this.
I think Lq mcDonald covered your basic mistake; but what I'm more worried about is:Recursion? Why?Ultimately I want to deploy this to a recursive function that will fill in an individual array for a great deal of the X and Y values in the first two dimensions of the array...
Tip: Use recursion only if you have to; and if the first two dimensions are 16 x 16 (or hell, 1024 x 1024) you probably don't need it.
Recursion (like reflection, which will probably be the next thing you run into that "looks nice on paper") is tough; particularly for those of us not well-versed in Maths and 'proof by induction'. If you like it, and still want to go with it, document it well for those of us that don't (and there are plenty other than me ).
Winston
T Shaw wrote:The function I'm trying to write is a pathfinding function. Given an object is initially at (X,Y), I need to know the most expedient combination of x+1, x-1, y+1, and y-1 moves to get to (x,y).
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|