#!/usr/bin/python def get_path(data): visited = [] loc = (0, 0) visited.append(loc) for d in data: if d == "^": loc = (loc[0], loc[1] + 1) elif d == "v": loc = (loc[0], loc[1] - 1) elif d == "<": loc = (loc[0] - 1, loc[1]) elif d == ">": loc = (loc[0] + 1, loc[1]) visited.append(loc) return visited def solve_part1(data): return len([*set(get_path(data))]) def solve_part2(data): data1 = data[0::2] data2 = data[1::2] return len([*set(get_path(data1) + get_path(data2))]) def main(): # Read delivery instructions from input text file with open("input.txt", "r") as f: data = f.read() print("Part 1 solution:", solve_part1(data)) # 2592 for me print("Part 2 solution:", solve_part2(data)) # 2360 for me if __name__ == "__main__": main()