7 int distance(int nw
, int n
, int ne
) {
8 // rotating path so all steps are positive results in same distance...
9 while (nw
< 0 || n
< 0 || ne
< 0) {
10 int tnw
= -ne
, tn
= nw
, tne
= n
;
27 int main(int argc
, char **argv
)
31 int nw
= 0, n
= 0, ne
= 0;
35 int max
= 0, dist
= 0;
36 while (*next
&& (next
= strchrnul(p
, ','))) {
39 n
+= *p
== 'n' ? 1 : -1;
49 dist
= distance(nw
, n
, ne
);
54 printf("after %d steps, nw=%d n=%d ne=%d\n", count
, nw
, n
, ne
);
55 printf("max distance %d, final distance %d\n", max
, dist
);