diff --git a/day07/part2.py b/day07/part2.py index d5aadc5..df7052e 100644 --- a/day07/part2.py +++ b/day07/part2.py @@ -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))) diff --git a/mathekalender.py b/mathekalender.py new file mode 100644 index 0000000..97d518f --- /dev/null +++ b/mathekalender.py @@ -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)