aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-12-08 01:06:09 +0100
committerThomas Voss <thomasvoss@live.com> 2021-12-08 01:06:09 +0100
commit02cf6a051d9629479df7d5a6d308153466563de6 (patch)
tree3d09f2c6002a769e93c49afdc64f1b0d05970ad4 /2021
parent3432015669c91ed073f2b3121948264840282df2 (diff)
Remove unused import and minor refactor
Diffstat (limited to '2021')
-rw-r--r--2021/07/puzzles.py21
1 files changed, 6 insertions, 15 deletions
diff --git a/2021/07/puzzles.py b/2021/07/puzzles.py
index bfd9bb3..a85016a 100644
--- a/2021/07/puzzles.py
+++ b/2021/07/puzzles.py
@@ -1,26 +1,17 @@
#!/usr/bin/env python3
-import math
+def main() -> None:
+ with open("input", "r", encoding="utf-8") as f:
+ data = list(map(int, f.read().split(",")))
-def gauss_sum(n: int) -> int:
# START PART 1
- return n
+ gauss_sum = lambda n: n
# END PART 1 START PART 2
- return n * (n + 1) // 2
+ gauss_sum = lambda n: 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)
- )
- )
+ print(min(sum(gauss_sum(abs(i - n)) for n in data) for i in range(min(data), max(data) + 1)))
if __name__ == "__main__":