Created
December 17, 2015 20:52
-
-
Save agentultra/bd9177ae4c210f984041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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