From cea2400d6f500897f4eff4ad05612cc4f6abbeaf Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 2 Dec 2024 16:21:25 -0500 Subject: [PATCH] 2024 day 2 part 1 solved --- 2024/2.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2024/2.py diff --git a/2024/2.py b/2024/2.py new file mode 100644 index 0000000..1a3ea1c --- /dev/null +++ b/2024/2.py @@ -0,0 +1,21 @@ +lines = [[int(n) for n in l.split()] for l in open("input.txt", 'r').read().splitlines()] + +unsafe, unsafe2 = 0, 0 + +for report in lines: + if report[0] == report[1]: + unsafe += 1 + continue + + trend = -1 if report[0] > report[1] else 1 + + for i in range(len(report) -1): + if (trend == -1 and report[i] < report[i+1]) \ + or (trend == 1 and report[i] > report[i+1]) \ + or (report[i] == report[i+1]) \ + or (abs(report[i] - report[i+1]) > 3): + + unsafe += 1 + break + +print(len(lines)-unsafe) \ No newline at end of file