0
0
Fork 0

Add code for 2015 advent that I did historically.

This commit is contained in:
Oliver-Akins 2020-12-06 20:33:17 -07:00
parent 13968ed94e
commit 9e9e556c73
25 changed files with 598 additions and 0 deletions

5
day_3/info.md Normal file
View file

@ -0,0 +1,5 @@
https://adventofcode.com/2015/day/3
north (`^`), south (`v`), east (`>`), or west (`<`)

37
day_3/part_1.py Normal file
View file

@ -0,0 +1,37 @@
# with open("input", "r") as data:
data = input()
unique_houses = 1
current_coord = [0, 0]
historic_coords = [f"{current_coord[0]},{current_coord[1]}"]
# Get each instruction
for direction in data:
# Heading north
if direction == "^": current_coord[1] += 1
# Heading south
elif direction == "v": current_coord[1] -= 1
# Heading west
elif direction == "<": current_coord[0] -= 1
# Heading east
elif direction == ">": current_coord[0] += 1
# Unknown input
else: raise Exception(f"InputError: Unexpected input: {direction}")
# Check if we've been here already
coord_string = f"{current_coord[0]},{current_coord[1]}"
if not (coord_string in historic_coords):
# New house, keep track of it
unique_houses += 1
historic_coords += [coord_string]
print(f"Total Houses With At Least One Present: {unique_houses}")

54
day_3/part_2.py Normal file
View file

@ -0,0 +1,54 @@
# with open("input", "r") as data:
data = input()
unique_houses = 1
santa_coord = [0, 0]
robo_coord = [0, 0]
historic_coords = [f"0,0"]
is_real_santa = True
# Get each instruction
for direction in data:
# Heading north
if direction == "^":
if is_real_santa: santa_coord[1] += 1
else: robo_coord[1] += 1
# Heading south
elif direction == "v":
if is_real_santa: santa_coord[1] -= 1
else: robo_coord[1] -= 1
# Heading west
elif direction == "<":
if is_real_santa: santa_coord[0] -= 1
else: robo_coord[0] -= 1
# Heading east
elif direction == ">":
if is_real_santa: santa_coord[0] += 1
else: robo_coord[0] += 1
# Unknown input
else: raise Exception(f"InputError: Unexpected input: {direction}")
# Get coordinate string
if is_real_santa: coord_string = f"{santa_coord[0]},{santa_coord[1]}"
else: f"{robo_coord[0]},{robo_coord[1]}"
# Check if we've been here already
if not (coord_string in historic_coords):
# New house, keep track of it
unique_houses += 1
historic_coords += [coord_string]
is_real_santa = not is_real_santa
print(f"Total Houses With At Least One Present: {unique_houses}")