31
Last seen 2 years ago
Member for 11 years, 5 months, 25 days
Difficulty Normal
If you want to avoid most of the if. You can use a dictionary like this:
dic = {'N': (1,0), 'S':(-1,0), 'W':(0,-1), 'E':(0,1)}
With this dictionary you can shrink getNextMove like this:
def getNextMove(data, i, j, path):
global visit
hasChanged = False
for d, vec
More
Compare to mine your solution he's realy easy to read but it isn't O(1) ;)
More
You successfully handle exceptions . Nice solution! (Finally not alone.:D )
More
Nice solution! It's a good idea to use a global strategy for each ghost/Stephen position.
Also, I would like to report a bug that I figured out when I've tested your code. In the attached file you can see that it crash for a specific case. I wander if you know why that happens?
More
EAST, WEST, SOUTH, NORTH = 'E','W','S','N',
Those variables aren't needed here.
More
Finally, you can change your getFirstMove like this:
def getFirstMove(data, i, j, startDir):
global visit
visit += [[1+dic[startDir][0], 1+dic[startDir][1]]]
return 1+dic[startDir][0], 1+dic[startDir][1], startDir
More
def visited(d):
I don't understand why you create this function. "d in visit" already return a boolean ;)
More
I didn't know the chinese remainder theorem. I think you can improve your algorithm if you take into account the first call ((1,5) in the example). Indeed, if they give you (1,8) you'll check two times the number 8. ;)
More
Using dir as a variable name isn't clean. Futhermore, it isn't necessary to add the path in the visited list. It works fine just with the position and with that you just have to check if the current position is in this list => no need for the isVisited function ;)
More
Why don't you use alkashi(b,c,a) instead of 180 - alkashi(a,b,c) - alkashi(a,c,b)?
More
map = [] # Yeah, global data bitches. It's faster.
Those comments... I love it :)
More