Skip to content

Commit ae57ab5

Browse files
committed
[main] Added functions
1 parent 2b7d7f5 commit ae57ab5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def diving_minigame(intervals):
2+
allowed_extra = 10
3+
curr_breath = 10
4+
for eachinterval in intervals:
5+
if curr_breath == 0:
6+
return False
7+
elif eachinterval >= 0 and curr_breath < 10:
8+
if allowed_extra > 0:
9+
extra_off = abs(curr_breath - 10)
10+
curr_breath += extra_off if extra_off <= 4 else 4
11+
allowed_extra -= extra_off if extra_off <= 4 else 4
12+
elif eachinterval < 0:
13+
curr_breath -= 2
14+
return curr_breath != 0
15+
16+
17+
if __name__ == '__main__':
18+
diving_minigame([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # True)
19+
diving_minigame([-5, -15, -4, 0, 5]) # True)
20+
diving_minigame([0, -4, 0, -4, -5, -2]) # True)
21+
diving_minigame([-4, -3, -4, -3, 5, 2, -5, -20, -42, -4, 5, 3, 5]) # True)
22+
23+
diving_minigame([-3, -6, -2, -6, -2]) # False)
24+
diving_minigame([-4, -5, -2, -7, 2, -1000, -2000, -1]) # False)
25+
diving_minigame([1, 2, 1, 2, 1, 2, 1, 2, 1, -3, -4, -5, -3, -4]) # False)
26+
diving_minigame([-5, -5, -5, -5, -5, 2, 2, 2, 2, 2, 2, 2, 2]) # False)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def maximum_seating(lst: list[int]):
2+
count = 0
3+
for i in range(len(lst)):
4+
left_bound = i - 2
5+
if sum(lst[left_bound if left_bound >= 0 else 0:i]) == 0 and sum(lst[i + 1: i + 3]) == 0 and lst[i] != 1:
6+
count += 1
7+
lst[i] = 1
8+
return count
9+
10+
11+
if __name__ == '__main__':
12+
print(maximum_seating([1, 0, 0, 0, 0, 0, 0, 1]))

0 commit comments

Comments
 (0)