2015 day 2 complete
This commit is contained in:
parent
f1df9f031c
commit
a71525e418
38
2015/3/part2.py
Normal file
38
2015/3/part2.py
Normal file
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue