Skip to content

Instantly share code, notes, and snippets.

@agentultra
Created December 17, 2015 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentultra/bd9177ae4c210f984041 to your computer and use it in GitHub Desktop.
Save agentultra/bd9177ae4c210f984041 to your computer and use it in GitHub Desktop.
import sys
def main(args=()):
x, y = 0, 0
total_presents = 1
visited = {(0, 0),}
with open('3-1.txt') as f:
directions = f.read(256)
while directions:
for d in directions:
if d == '<':
x -= 1
elif d == '>':
x += 1
elif d == '^':
y -= 1
elif d == 'v':
y += 1
if ((x, y) not in visited):
visited.add((x, y))
total_presents += 1
directions = f.read(256)
print('Santa delivered %d presents' % total_presents)
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment