Skip to content

Instantly share code, notes, and snippets.

@Tomalak
Forked from spielkind/day2.py
Last active December 2, 2021 17:55
Show Gist options
  • Save Tomalak/3d71b14f82db0432252fcc6eeb1add3a to your computer and use it in GitHub Desktop.
Save Tomalak/3d71b14f82db0432252fcc6eeb1add3a to your computer and use it in GitHub Desktop.
#!/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