Day 07 (glamorized)

This commit is contained in:
Sebastian Seedorf
2021-12-07 10:47:52 +01:00
parent de09a3a78c
commit 530d103717
2 changed files with 31 additions and 2 deletions

View File

@@ -4,5 +4,6 @@ lines = (list(map(int, x.strip().split(','))) for x in open("input.txt"))
for line in lines:
line.sort()
median = round(sum(line) / len(line))
print(min(sum(abs(x - m)*(abs(x - m)+1)//2 for x in line) for m in range(median-1, median+2)))
mean = round(sum(line) / len(line))
# fix of by one error
print(min(sum(abs(x - m)*(abs(x - m)+1)//2 for x in line) for m in range(mean-1, mean+2)))

28
mathekalender.py Normal file
View File

@@ -0,0 +1,28 @@
from itertools import combinations
names = ["Eisstedt", "Frostberg", "Gletscherdorf", "Kaltburg", "Schneeheim", "Winterthal"]
games = list(combinations(names, 2))
table = {name: 0 for name in names}
def play(idx):
if idx >= len(games):
yield []
else:
[a, b] = games[idx]
table[a] += 3
yield from map(lambda x: ["{} > {}".format(a[0], b[0])] + x, play(idx+1))
table[a] -= 2
table[b] += 1
yield from map(lambda x: ["{} = {}".format(a[0], b[0])] + x, play(idx+1))
table[a] -= 1
table[b] += 2
yield from map(lambda x: ["{} < {}".format(a[0], b[0])] + x, play(idx+1))
table[b] -= 3
for playouts in play(0):
success = all(table[a]-2 == table[b] for a, b in zip(names[:-1], names[1:]))
if success:
print(table)
print(playouts)