From a71525e418c563c73ed5ea20846eef34aad4cb6c Mon Sep 17 00:00:00 2001 From: Tristan Date: Fri, 30 Nov 2018 13:53:25 +0000 Subject: [PATCH] 2015 day 2 complete --- 2015/3/part2.py | 38 ++++++++++++++++++++++++++++++++++++++ README.md | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 2015/3/part2.py diff --git a/2015/3/part2.py b/2015/3/part2.py new file mode 100644 index 0000000..e303b15 --- /dev/null +++ b/2015/3/part2.py @@ -0,0 +1,38 @@ + +# lets just make it object oriented wtf +class Dud (): + def __init__ (self): + self.x = 0 + self.y = 1 + + def do(self, command): + if command == ">": + self.x += 1 + elif command == "<": + self.x -= 1 + elif command == "^": + self.y += 1 + elif command == "v": + self.y -= 1 + + +with open("input.txt", "r") as commands: + santa = Dud() + robo = Dud() + + history = set() + num = 0 + for command in commands.readlines()[0]: + dud = santa if num % 2 == 0 else robo + dud.do(command) + + history.add((dud.x, dud.y)) + + num += 1 + print(len(history)) + commands.close() + + + + + diff --git a/README.md b/README.md index 89d34dd..7c9c562 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ It's a fun challenge from [here](https://adventofcode.com). * [2015](https://adventofcode.com/2015) * [1](https://adventofcode.com/2015/day/1) * * * [2](https://adventofcode.com/2015/day/2) * * - * [2](https://adventofcode.com/2015/day/3) + * [3](https://adventofcode.com/2015/day/3) * * + * [4](https://adventofcode.com/2015/day/4) * [2016](https://adventofcode.com/2016) * [2017](https://adventofcode.com/2017) * [2018](https://adventofcode.com/2018)