BEGIN{P["0_0"]=1; Hx=Hy=Tx=Ty=0} function abs(x) { return x>0?x:-x} { print "==", Hx","Hy, ";", Tx","Ty, "==", $1, $2 for(i=1;i<=$2;i++){ if($1=="R") {Hx++} if($1=="L") {Hx--} if($1=="U") {Hy++} if($1=="D") {Hy--} dh = abs(Hx-Tx) # tension horizontale dv = abs(Hy-Ty) # tension vertivale if(dh>1 && $1=="R") {Tx++; if (dv>0) {Ty=Hy}} if(dh>1 && $1=="L") {Tx--; if (dv>0) {Ty=Hy}} if(dv>1 && $1=="U") {Ty++; if (dh>0) {Tx=Hx}} if(dv>1 && $1=="D") {Ty--; if (dh>0) {Tx=Hx}} P[Ty "_" Tx]=1 print Hx, Hy, ";", "dh:"dh, "dv:"dv, "=>", Tx, Ty } } END{print length(P)}