Day 07 (glamorized)
This commit is contained in:
@@ -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
28
mathekalender.py
Normal 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)
|
||||
Reference in New Issue
Block a user