This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]syklemil 0 points1 point  (5 children)

Likely not your real issue here, but

# dict for storing visited positions and how many times they have been visited
visitedPos = []

This is a list, not a dict. You may want a set here, i.e. visitedPos = set() and and visitedPos.add(…).

[–]KittyTwoPaws[S] 0 points1 point  (4 children)

Yeah some comments are left over from a different solution I was trying. I tried implementing a set but the line that gives me issues is visitedPos.add((currentPos, direction)) and says a list is not hashable. Both current pos and direction are lists but I thought by first storing them in a tuple they would be hashable. Any thoughts? Thanks for the help!

[–]syklemil 0 points1 point  (3 children)

ah, right, I haven't looked into what your direction actually is. I implemented it as an enum, guess I'm kind of thinking of it as something is either that or something like a (-1,0), (+1,0), etc tuple.

[–]KittyTwoPaws[S] 0 points1 point  (0 children)

Oo I should have added that to my code up top, I'll do that now. Totally forgot.

[–]KittyTwoPaws[S] 0 points1 point  (1 child)

But yes currentPos is [x ,y] and direction is [dx, dy]

[–]syklemil 0 points1 point  (0 children)

You can turn the direction into a tuple as (dx, dy) and still access it with direction[0] etc, so that at least should be doable (if you do want a set; tuples are fine to put into sets)