-
-
Save Tomalak/3d71b14f82db0432252fcc6eeb1add3a to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/python | |
class Submarine(): | |
def __init__(self): | |
self.horizontal = 0 | |
self.depth = 0 | |
self.aim = 0 | |
def forward(self, amount): | |
self.horizontal += amount | |
self.depth += amount * self.aim | |
def up(self, amount): | |
self.aim -= amount | |
def down(self, amount): | |
self.aim += amount | |
sub = Submarine() | |
with open('day2.txt') as f: | |
for line in f: | |
c, a = line.split() | |
getattr(sub, c)(int(a)) | |
print(f'Part Two: {sub.depth * sub.horizontal}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment