Skip to content

Commit abcfac6

Browse files
committed
added 2015/day13
1 parent d692086 commit abcfac6

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

2015/day13/answers.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
733
2+
725

2015/day13/input.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Alice would gain 2 happiness units by sitting next to Bob.
2+
Alice would gain 26 happiness units by sitting next to Carol.
3+
Alice would lose 82 happiness units by sitting next to David.
4+
Alice would lose 75 happiness units by sitting next to Eric.
5+
Alice would gain 42 happiness units by sitting next to Frank.
6+
Alice would gain 38 happiness units by sitting next to George.
7+
Alice would gain 39 happiness units by sitting next to Mallory.
8+
Bob would gain 40 happiness units by sitting next to Alice.
9+
Bob would lose 61 happiness units by sitting next to Carol.
10+
Bob would lose 15 happiness units by sitting next to David.
11+
Bob would gain 63 happiness units by sitting next to Eric.
12+
Bob would gain 41 happiness units by sitting next to Frank.
13+
Bob would gain 30 happiness units by sitting next to George.
14+
Bob would gain 87 happiness units by sitting next to Mallory.
15+
Carol would lose 35 happiness units by sitting next to Alice.
16+
Carol would lose 99 happiness units by sitting next to Bob.
17+
Carol would lose 51 happiness units by sitting next to David.
18+
Carol would gain 95 happiness units by sitting next to Eric.
19+
Carol would gain 90 happiness units by sitting next to Frank.
20+
Carol would lose 16 happiness units by sitting next to George.
21+
Carol would gain 94 happiness units by sitting next to Mallory.
22+
David would gain 36 happiness units by sitting next to Alice.
23+
David would lose 18 happiness units by sitting next to Bob.
24+
David would lose 65 happiness units by sitting next to Carol.
25+
David would lose 18 happiness units by sitting next to Eric.
26+
David would lose 22 happiness units by sitting next to Frank.
27+
David would gain 2 happiness units by sitting next to George.
28+
David would gain 42 happiness units by sitting next to Mallory.
29+
Eric would lose 65 happiness units by sitting next to Alice.
30+
Eric would gain 24 happiness units by sitting next to Bob.
31+
Eric would gain 100 happiness units by sitting next to Carol.
32+
Eric would gain 51 happiness units by sitting next to David.
33+
Eric would gain 21 happiness units by sitting next to Frank.
34+
Eric would gain 55 happiness units by sitting next to George.
35+
Eric would lose 44 happiness units by sitting next to Mallory.
36+
Frank would lose 48 happiness units by sitting next to Alice.
37+
Frank would gain 91 happiness units by sitting next to Bob.
38+
Frank would gain 8 happiness units by sitting next to Carol.
39+
Frank would lose 66 happiness units by sitting next to David.
40+
Frank would gain 97 happiness units by sitting next to Eric.
41+
Frank would lose 9 happiness units by sitting next to George.
42+
Frank would lose 92 happiness units by sitting next to Mallory.
43+
George would lose 44 happiness units by sitting next to Alice.
44+
George would lose 25 happiness units by sitting next to Bob.
45+
George would gain 17 happiness units by sitting next to Carol.
46+
George would gain 92 happiness units by sitting next to David.
47+
George would lose 92 happiness units by sitting next to Eric.
48+
George would gain 18 happiness units by sitting next to Frank.
49+
George would gain 97 happiness units by sitting next to Mallory.
50+
Mallory would gain 92 happiness units by sitting next to Alice.
51+
Mallory would lose 96 happiness units by sitting next to Bob.
52+
Mallory would lose 51 happiness units by sitting next to Carol.
53+
Mallory would lose 81 happiness units by sitting next to David.
54+
Mallory would gain 31 happiness units by sitting next to Eric.
55+
Mallory would lose 73 happiness units by sitting next to Frank.
56+
Mallory would lose 89 happiness units by sitting next to George.

2015/day13/run.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /usr/bin/env python3
2+
3+
def load_data(filename):
4+
with open(filename, 'r') as f:
5+
for line in f:
6+
line = line.rstrip('\n')
7+
m = re.match(r'^(\w+) would (gain|lose) (\d+) happiness units by sitting next to (\w+)\.$', line).groups()
8+
yield m[0], (-1 if m[1] == 'lose' else 1) * int(m[2]), m[3]
9+
10+
# Part One
11+
12+
import re
13+
from itertools import permutations
14+
15+
preferences = {}
16+
for who, score, withwhom in load_data('input.txt'):
17+
if who not in preferences:
18+
preferences[who] = {}
19+
preferences[who][withwhom] = score
20+
21+
attendees = set(preferences.keys())
22+
23+
def happiness(order):
24+
total = 0
25+
for i, who in enumerate(order):
26+
total += preferences[who].get(order[i-1], 0)
27+
total += preferences[who].get(order[(i+1) % len(order)], 0)
28+
return total
29+
30+
result = max( happiness(order) for order in permutations(attendees) )
31+
32+
print(result)
33+
34+
# Part Two
35+
36+
preferences["Me"] = {}
37+
attendees.add("Me")
38+
39+
result = max( happiness(order) for order in permutations(attendees) )
40+
41+
print(result)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
```
22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
3-
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- +-
3+
2015 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- +-
44
2016 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- --
55
2017 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- --
66
2018 ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ -- -- -- -- -- -- -- -- -- -- -- -- +-

0 commit comments

Comments
 (0)