diff options
author | blenovo <bk@gmail.com> | 2024-12-15 21:35:41 +0100 |
---|---|---|
committer | blenovo <bk@gmail.com> | 2024-12-15 21:35:41 +0100 |
commit | b96161d57f868e32792b8af631fa76edd89b543c (patch) | |
tree | 9b6dca211de153ceabec282e3269cea2190adde5 /2024/aoc2024-d02.py | |
parent | b00dd9290d19d4e670b2fff3d9f1b29cdd5aa59e (diff) |
finally restored git access so adding 2024, days 01-15
Diffstat (limited to '2024/aoc2024-d02.py')
-rw-r--r-- | 2024/aoc2024-d02.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/2024/aoc2024-d02.py b/2024/aoc2024-d02.py new file mode 100644 index 0000000..655fdc1 --- /dev/null +++ b/2024/aoc2024-d02.py @@ -0,0 +1,41 @@ +#advent of code 2024 +#day 02 +part1 = 0; +ToCheck = []; + +f = open("02.in","r"); +for l in f: + levels = [int(lvl) for lvl in l.split()]; + if (levels[1]-levels[0]) < 0: + levels.reverse(); + dMin = 4; + dMax = 0; + for i in range(1,len(levels)): + d = levels[i] - levels[i-1]; + dMin = min(dMin,d); + dMax = max(dMax,d); + if dMax <=3 and dMin >= 1: + part1 += 1; + else: + ToCheck.append(levels); +f.close(); + +correction = 0; +for levels in ToCheck: + isOK = False; + for x in range(len(levels)): + NewLevels = [levels[y] for y in range(len(levels)) if y !=x] + for _ in ["n","r"]: #normal and reversed, reverse and the end of first iteration + dMin = 4; + dMax = 0; + for i in range(1,len(NewLevels)): + d = NewLevels[i] - NewLevels[i-1]; + dMin = min(dMin,d); + dMax = max(dMax,d); + if dMax <=3 and dMin >= 1: isOK = True; + NewLevels.reverse(); + if isOK: correction += 1; + +part2 = part1 + correction; +print("part 1 = ", part1); +print("part 2 = ", part2); |