I am looking to cross the NxN area, given the starting points X, Y and the size of the square to move. For example. given X = 10, Y = 12, size = 2 - I want to generate 10.10; 10.11; 11.10 and 11.11.
I came up with this, but it looks like it goes on endlessly:
traverse({X,Y,Xend,Yend}) ->
% print X,Y values here....
case (X == Xend-1) andalso (Y == Yend-1) of
true ->
ok;
_->
case (Y < Yend-1) of
true ->
traverse({X,Y+1,Xend,Yend});
_->
traverse({X+1,Y,Xend,Yend})
end
end.
I called the above function from another function using:
Size = 3,
traverse({10,20,10+Size,20+Size}).
What am I doing wrong? I'm actually new to the functional paradigm, and I tried to implement this in C using "return" instead of "ok" above, and it worked, but I guess I don't think "functionally" enough!
source
share