-
-
Save ravgoundar/74d774f74318cd5762bb to your computer and use it in GitHub Desktop.
var inputs = readline().split(' '); | |
var LX = parseInt(inputs[0]); | |
var LY = parseInt(inputs[1]); | |
var TX = parseInt(inputs[2]); | |
var TY = parseInt(inputs[3]); | |
while (true) { | |
var E = parseInt(readline()); | |
if (TY == LY) { | |
if (TX < LX) { | |
print('E'); | |
TX++; | |
} else { | |
print('W') | |
TX--; | |
} | |
} else if (TY > LY) { | |
if (TX == LX) { | |
print('N'); | |
printErr(TY); | |
TY--; | |
} else if (TX > LX) { | |
print('NW'); | |
TX--; | |
TY--; | |
} else { | |
print('NE'); | |
TX++; | |
TY--; | |
} | |
} else if (TY < LY) { | |
if (TX == LX) { | |
print('S'); | |
TY++; | |
} else if (TX > LX) { | |
print('SW'); | |
TX--; | |
TY++; | |
} else { | |
print('SE'); | |
TX++; | |
TY++; | |
} | |
} | |
} |
It is so that when it is doing the IF check it is making sure that the new coordinate of Thor is still greater/less than the light. If it did not add one to the position when he moved then it would always be a passing case, and Thor would move off the field.
@RayRayG Lol dude, I don't mean to be rude, but this is a code golf challenge and you're supposed to solve it in the least amount of characters.
Example 1 (91 characters, but with cheating, cause it uses hardcoded values):
o={7:'W',5:'S'},a=+readline()[0];for(i=0;;i++)print(a>3?o[a]:a?i>13?'E':'SE':i>16?'W':'SW')
Example 2 (173 characters, but without cheating and without hardcoding anything, and could be further improved):
c=readline().split(' ').map(Number);while(1)(c[3]>c[1]?(d='N',c[3]--):(c[3]<c[1]?(d='S',c[3]++):d=''))+(c[2]>c[0]?(d+='W',c[2]--):(c[2]<c[0]?(d+='E',c[2]++):d+='')),print(d)
Hi, great solution! It really helps me a lot. But as I am a beginner, I'd like to ask some questions. Main one is: can you please elaborate line 12 ? As far as I understand, TX++ should mean that X coordinate of Thor must be increased by 1. However I don't get it why we need to do that at line 12, 15, 21 etc.