Created
December 2, 2021 06:22
-
-
Save tobidope/93d67ab1a11fd340726d27aace99b631 to your computer and use it in GitHub Desktop.
AOC2021 day2
This file contains hidden or 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
| data = """ | |
| """ | |
| def solve1(data): | |
| hpos = 0 | |
| depth = 0 | |
| for instruction in data.splitlines(): | |
| direction, number = instruction.split() | |
| number = int(number) | |
| if direction == "forward": | |
| hpos += number | |
| elif direction == "up": | |
| depth -= number | |
| elif direction == "down": | |
| depth += number | |
| return hpos, depth | |
| def solve2(data): | |
| hpos = 0 | |
| depth = 0 | |
| aim = 0 | |
| for instruction in data.splitlines(): | |
| direction, number = instruction.split() | |
| number = int(number) | |
| if direction == "forward": | |
| hpos += number | |
| depth += aim * number | |
| elif direction == "up": | |
| aim -= number | |
| elif direction == "down": | |
| aim += number | |
| return hpos, depth | |
| hpos, depth = solve1(data) | |
| print(f"Day 1.1 - {hpos}, {depth} = {hpos*depth}") | |
| hpos, depth = solve2(data) | |
| print(f"Day 1.2 - {hpos}, {depth} = {hpos*depth}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment