diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-02 06:15:47 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-02 06:37:33 +0100 |
| commit | c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00 (patch) | |
| tree | f0ae0f3e09b748aafb3effba7051eb8e136c55e1 /2025/02/a.py | |
| parent | 8e716a225ece98cf75cc1789c8f90757c0beadfc (diff) | |
| download | aoc-c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00.tar.gz aoc-c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00.zip | |
Day 2 2025 (solved part 2 before part 1 because I misread lol)
Diffstat (limited to '2025/02/a.py')
| -rw-r--r-- | 2025/02/a.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/2025/02/a.py b/2025/02/a.py index 5fdb11b..9c6fd84 100644 --- a/2025/02/a.py +++ b/2025/02/a.py | |||
| @@ -1,6 +1,17 @@ | |||
| 1 | import fileinput | 1 | import fileinput |
| 2 | 2 | ||
| 3 | def invalid(n): | ||
| 4 | return n[:len(n)//2] == n[len(n)//2:] | ||
| 5 | |||
| 6 | s = 0 | ||
| 3 | with fileinput.input() as lines: | 7 | with fileinput.input() as lines: |
| 4 | for line in lines: | 8 | for line in lines: |
| 5 | ... | 9 | for r in line.split(","): |
| 10 | l = r.split("-"); | ||
| 11 | for n in range(int(l[0]), int(l[1])+1): | ||
| 12 | if invalid(str(n)): | ||
| 13 | print(n) | ||
| 14 | s += n | ||
| 15 | print(s) | ||
| 16 | |||
| 6 | 17 | ||
