diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 06:54:43 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-01 06:54:43 +0100 |
| commit | bdcdf6f58271008c590ac9157e73c901280d092a (patch) | |
| tree | fe1ff8082da15b22392d4e937e83ac5d83f11fa0 /2025/01 | |
| parent | 3e40017c5e856fbbc33bbdd53a9a8e1d2b02abd8 (diff) | |
| download | aoc-bdcdf6f58271008c590ac9157e73c901280d092a.tar.gz aoc-bdcdf6f58271008c590ac9157e73c901280d092a.zip | |
Day 1 I am stupid and I don't know why
Diffstat (limited to '2025/01')
| -rw-r--r-- | 2025/01/a.py | 8 | ||||
| -rw-r--r-- | 2025/01/b.py | 19 |
2 files changed, 26 insertions, 1 deletions
diff --git a/2025/01/a.py b/2025/01/a.py index 5fdb11b..114acb4 100644 --- a/2025/01/a.py +++ b/2025/01/a.py | |||
| @@ -1,6 +1,12 @@ | |||
| 1 | import fileinput | 1 | import fileinput |
| 2 | 2 | ||
| 3 | p = 50 | ||
| 4 | c = 0 | ||
| 3 | with fileinput.input() as lines: | 5 | with fileinput.input() as lines: |
| 4 | for line in lines: | 6 | for line in lines: |
| 5 | ... | 7 | s = 1 if line[0] == "R" else -1 |
| 8 | p = (p + s * int(line[1:])) % 100 | ||
| 9 | if p == 0: | ||
| 10 | c += 1 | ||
| 6 | 11 | ||
| 12 | print(c) | ||
diff --git a/2025/01/b.py b/2025/01/b.py new file mode 100644 index 0000000..ea32dc7 --- /dev/null +++ b/2025/01/b.py | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | p = 50 | ||
| 4 | c = 0 | ||
| 5 | with fileinput.input() as lines: | ||
| 6 | for line in lines: | ||
| 7 | oldp = p | ||
| 8 | s = 1 if line[0] == "R" else -1 | ||
| 9 | p += s * int(line[1:]) | ||
| 10 | if p >= 100: | ||
| 11 | d = p // 100 | ||
| 12 | c += d | ||
| 13 | p -= d * 100 | ||
| 14 | elif p <= 0: | ||
| 15 | d = -p // 100 + 1 | ||
| 16 | c += d if oldp != 0 else d-1 | ||
| 17 | p = (p + d * 100) % 100 | ||
| 18 | |||
| 19 | print(c) | ||
