aboutsummaryrefslogtreecommitdiff
path: root/2021/07/puzzles.py
blob: bfd9bb325adf530803f1794a291c6ccabb4811c8 (plain) (blame)
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
26
27
#!/usr/bin/env python3

import math


def gauss_sum(n: int) -> int:
	# START PART 1
	return n
	# END PART 1 START PART 2
	return n * (n + 1) // 2
	# END PART 2


def main() -> None:
	with open("input", "r", encoding="utf-8") as f:
		data = list(map(int, f.read().split(",")))

	print(
		min(
			sum(gauss_sum(abs(i - data[j])) for j in range(len(data)))
			for i in range(min(data), max(data) + 1)
		)
	)


if __name__ == "__main__":
	main()