summaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorFanDabbyDoozy <ps20163152@student.vsa.edu.hk>2024-12-04 21:55:35 +0800
committerGitHub <noreply@github.com>2024-12-04 21:55:35 +0800
commitcf052f66f8644d7271f25ea24624737e8556d301 (patch)
tree97d7e48a5927245dd6b787b7c3e6e891ba25f7b4 /2024
parentc05f73f8232f4b0f431a355e0108a2032fb73a6e (diff)
Create 2B.py
Diffstat (limited to '2024')
-rw-r--r--2024/2B.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/2024/2B.py b/2024/2B.py
new file mode 100644
index 0000000..cb6d86d
--- /dev/null
+++ b/2024/2B.py
@@ -0,0 +1,55 @@
+res = 0
+
+
+vals = []
+with open('2.txt', 'r') as file:
+ for line in file:
+ parts = line.strip().split(" ")
+ inlist = []
+ for num in parts:
+ inlist.append(int(num))
+ vals.append(inlist)
+
+
+slists = []
+
+
+for val in vals:
+ print(val)
+ isafe = False
+
+ for i in range(len(val)):
+ row = val.copy()
+ row.pop(i)
+ print(row)
+
+
+ increasing = False
+ decreasing = False
+ safe = True
+ prev = -1
+
+ for j in row:
+ if prev == -1:
+ prev = j
+ continue
+ if prev < j:
+ increasing = True
+ elif prev > j:
+ decreasing = True
+ if (abs(prev - j) > 3 or prev == j or
+ (j > prev and decreasing) or (j < prev and increasing) or
+ (increasing and decreasing) or (not increasing and not decreasing)):
+ safe = False
+ break
+ prev = j
+
+ if safe:
+ isafe = True
+ break
+
+ slists.append(isafe)
+
+res = sum(slists)
+
+print(res)