diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-07 06:16:27 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-07 06:16:27 +0100 |
commit | 8ebd49714cf7e8dec2f119d4ba6f44f485d0e8c7 (patch) | |
tree | 4d023ee744d0c25bb78ad2e94682e54c3607e376 /2021/07/puzzles.py | |
parent | e984cdcd76fd861b8ec633f15f0f4255394c22d1 (diff) |
Add day 7 solutions
Diffstat (limited to '2021/07/puzzles.py')
-rw-r--r-- | 2021/07/puzzles.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/2021/07/puzzles.py b/2021/07/puzzles.py new file mode 100644 index 0000000..b0ccb32 --- /dev/null +++ b/2021/07/puzzles.py @@ -0,0 +1,22 @@ +#!/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(max(data)))) + + +if __name__ == "__main__": + main() |