Skip to content

Commit 8904f9d

Browse files
committed
Add 2015 Day 9
1 parent 7642401 commit 8904f9d

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

2015/9/2015_09.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# --- Day 9: All in a Single Night ---
2+
3+
Every year, Santa manages to deliver all of his presents in a single night.
4+
5+
This year, however, he has some new locations to visit; his elves have provided him the distances between every pair of locations. He can start and end at any two (different) locations he wants, but he must visit each location exactly once. What is the shortest distance he can travel to achieve this?
6+
7+
For example, given the following distances:
8+
9+
```text
10+
London to Dublin = 464
11+
London to Belfast = 518
12+
Dublin to Belfast = 141
13+
```
14+
15+
The possible routes are therefore:
16+
17+
```text
18+
Dublin -> London -> Belfast = 982
19+
London -> Dublin -> Belfast = 605
20+
London -> Belfast -> Dublin = 659
21+
Dublin -> Belfast -> London = 659
22+
Belfast -> Dublin -> London = 605
23+
Belfast -> London -> Dublin = 982
24+
```
25+
26+
The shortest of these is `London -> Dublin -> Belfast = 605`, and so the answer is 605 in this example.
27+
28+
What is the distance of the shortest route?

2015/9/2015_09.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
AlphaCentauri to Snowdin = 66
2+
AlphaCentauri to Tambi = 28
3+
AlphaCentauri to Faerun = 60
4+
AlphaCentauri to Norrath = 34
5+
AlphaCentauri to Straylight = 34
6+
AlphaCentauri to Tristram = 3
7+
AlphaCentauri to Arbre = 108
8+
Snowdin to Tambi = 22
9+
Snowdin to Faerun = 12
10+
Snowdin to Norrath = 91
11+
Snowdin to Straylight = 121
12+
Snowdin to Tristram = 111
13+
Snowdin to Arbre = 71
14+
Tambi to Faerun = 39
15+
Tambi to Norrath = 113
16+
Tambi to Straylight = 130
17+
Tambi to Tristram = 35
18+
Tambi to Arbre = 40
19+
Faerun to Norrath = 63
20+
Faerun to Straylight = 21
21+
Faerun to Tristram = 57
22+
Faerun to Arbre = 83
23+
Norrath to Straylight = 9
24+
Norrath to Tristram = 50
25+
Norrath to Arbre = 60
26+
Straylight to Tristram = 27
27+
Straylight to Arbre = 81
28+
Tristram to Arbre = 90

2015/9/2015_09_01.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Advent of Code 2015, Day 9: All in a Single Night. Part 1
2+
# https://adventofcode.com/2015/day/9
3+
4+
import re
5+
import networkx as nx
6+
7+
8+
def main():
9+
solution = 0
10+
pairings = []
11+
12+
# Get pairings and distances from file
13+
for line in open("./2015/9/2015_09.txt", "r", encoding="utf-8"):
14+
pairings.append(re.split(r" to | = ", line.strip()))
15+
16+
# Build graph
17+
G = nx.Graph()
18+
for pairing in pairings:
19+
G.add_edge(pairing[0], pairing[1], weight=int(pairing[2]))
20+
21+
# Find shortest path visiting every node exactly once by brute force
22+
23+
24+
return f"The shortest possible distance is {solution}"
25+
26+
27+
if __name__ == "__main__":
28+
print(main())

2015/9/2015_09_02.py

Whitespace-only changes.

0 commit comments

Comments
 (0)