aboutsummaryrefslogtreecommitdiff
path: root/2021/07/puzzles.py
blob: a85016a92ef22e97e7b09b11a5d7bb8c768588b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3


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

	# START PART 1
	gauss_sum = lambda n: n
	# END PART 1 START PART 2
	gauss_sum = lambda n: n * (n + 1) // 2
	# END PART 2

	print(min(sum(gauss_sum(abs(i - n)) for n in data) for i in range(min(data), max(data) + 1)))


if __name__ == "__main__":
	main()