-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmexFunction.py
More file actions
15 lines (12 loc) · 966 Bytes
/
Copy pathmexFunction.py
File metadata and controls
15 lines (12 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# You've just started to study impartial games, and came across an interesting theory. The theory is quite complicated, but it can be narrowed down to the following statements: solutions to all such games can be found with the mex function. Mex is an abbreviation of minimum excludant: for the given set s it finds the minimum non-negative integer that is not present in s.
# You don't yet know how to implement such a function efficiently, so would like to create a simplified version. For the given set s and given an upperBound, implement a function that will find its mex if it's smaller than upperBound or return upperBound instead.
# Hint: for loops also have an else clause which executes when the loop completes normally, i.e. without encountering any breaks
def mexFunction(s, upperBound):
found = -1
for i in range(upperBound):
if not i in s:
found = i
break
else:
found = upperBound
return found