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

6
day_9/info.md Normal file
View file

@ -0,0 +1,6 @@
https://adventofcode.com/2015/day/9
Part 2 Incorrect Answers:
- `361`
- `764`

69
day_9/part_1.py Normal file
View file

@ -0,0 +1,69 @@
def find_shortest_distance(directions, location, visited_locations = []):
min_location = ["", None]
# Iterate through places we can travel to
for direction in directions[location]:
if direction in visited_locations:
continue
# find the shortest destination
if min_location[1]:
if directions[location][direction] < min_location[1]:
min_location = [
direction,
directions[location][direction]
]
else:
min_location = [
direction,
directions[location][direction]
]
return min_location
def find_shortest_route(directions, start):
current_location = start
distance_travelled = 0
visited_locations = []
while len(visited_locations) < len(directions):
shortest_route = find_shortest_distance(directions, current_location, visited_locations)
if not shortest_route[1]: break
visited_locations.append(current_location)
distance_travelled += shortest_route[1]
current_location = shortest_route[0]
return distance_travelled
def create_map():
locale = {}
with open("input", "r") as file:
for line in file:
data = line.strip().split()
# Ensure city hasn't already been assigned
if data[0] not in locale:
locale[data[0]] = {}
locale[data[0]][data[2]] = int(data[-1])
# Ensure city hasn't already been assigned
if data[2] not in locale:
locale[data[2]] = {}
locale[data[2]][data[0]] = int(data[-1])
return locale
locations = create_map()
distances = []
for location in locations:
distances.append(find_shortest_route(
locations,
location
))
print(f"Shortest Route: {min(distances)}")

16
day_9/text.js Normal file
View file

@ -0,0 +1,16 @@
let potato = {
'.Faerun': {'Norrath': 129, 'Tristram': 58, 'AlphaCentauri': 13, 'Arbre': 24, 'Snowdin': 60, 'Tambi': 71, 'Straylight': 67},
'.Norrath': {'Faerun': 129, 'Tristram': 142, 'AlphaCentauri': 15, 'Arbre': 135, 'Snowdin': 75, 'Tambi': 82, 'Straylight': 54},
'.Tristram': {'Faerun': 58, 'Norrath': 142, 'AlphaCentauri': 118, 'Arbre': 122, 'Snowdin': 103, 'Tambi': 49, 'Straylight': 97},
'.AlphaCentauri': {'Faerun': 13, 'Norrath': 15, 'Tristram': 118, 'Arbre': 116, 'Snowdin': 12, 'Tambi': 18, 'Straylight': 91},
'.Arbre': {'Faerun': 24, 'Norrath': 135, 'Tristram': 122, 'AlphaCentauri': 116, 'Snowdin': 129, 'Tambi': 53, 'Straylight': 40},
'.Snowdin': {'Faerun': 60, 'Norrath': 75, 'Tristram': 103, 'AlphaCentauri': 12, 'Arbre': 129, 'Tambi': 15, 'Straylight': 99},
'.Tambi': {'Faerun': 71, 'Norrath': 82, 'Tristram': 49, 'AlphaCentauri': 18, 'Arbre': 53, 'Snowdin': 15, 'Straylight': 70},
'.Straylight': {'Faerun': 67, 'Norrath': 54, 'Tristram': 97, 'AlphaCentauri': 91, 'Arbre': 40, 'Snowdin': 99, 'Tambi': 70}};
/*
Faerun (0) -> Norrath (+129) -> Tristram (+142) -> Arbre (+122) -> Snowdin (+129) -> Straylight (+99) -> AlphaCentauri (+91) -> Tambi (+15)
AlphaCentauri (0) -> Tristram (+118) -> Norrath (+142) -> Arbre (+135) -> Snowdin (+129) -> Straylight (+99) -> Tambi (+70) -> Faerun (+71) ==== 764
*/