diff --git a/2015/days/03/walk.py b/2015/days/03/walk.py new file mode 100644 index 0000000..463dcaf --- /dev/null +++ b/2015/days/03/walk.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +count = 0 +x = 0 +y = 0 +visited = {} + +MOTION = { + "^": [0, -1], + "<": [-1, 0], + "v": [0, 1], + ">": [1, 0] +} + +def move(char): + global x + global y + motion = MOTION[char] + x += motion[0] + y += motion[1] + visit(x, y) + +def visit(x, y): + global count + if (x, y) not in visited: + visited[(x, y)] = 1 + count += 1 + +visit(x, y) +with open("./data/input", "r") as f: + for line in f: + for char in line: + move(char) +print(count)