Add code for 2015 advent that I did historically.
This commit is contained in:
parent
13968ed94e
commit
9e9e556c73
25 changed files with 598 additions and 0 deletions
37
day_3/part_1.py
Normal file
37
day_3/part_1.py
Normal 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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue