diff options
| author | mhsn <mail@mhsn.net> | 2025-12-02 19:51:09 +0000 |
|---|---|---|
| committer | mhsn <mail@mhsn.net> | 2025-12-02 19:51:09 +0000 |
| commit | 55b550b3f901edf10073e3e04ca52997422206ac (patch) | |
| tree | 986ae62effe6ea02b0419217697a52aa11814963 | |
| parent | def7ab6f54d52319f394c235aa6664a1a99309cd (diff) | |
| download | aoc-55b550b3f901edf10073e3e04ca52997422206ac.tar.gz aoc-55b550b3f901edf10073e3e04ca52997422206ac.zip | |
25-02 python p1
| -rwxr-xr-x | 2025/02/python.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/2025/02/python.py b/2025/02/python.py new file mode 100755 index 0000000..2e55ec1 --- /dev/null +++ b/2025/02/python.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +from fileinput import input +from math import log10 + +rs = [[int(i) for i in r.split("-")] for r in "".join(input()).split(",")] + + +def invalid(i): + d = int(log10(i)) + 1 + a, b = divmod(i, 10 ** (d // 2)) + return a == b + + +silver = sum(x for [a, b] in rs for x in range(a, b + 1) if invalid(x)) +gold = 0 + +print("silver:", silver) +print("gold:", gold) |
