-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrust.py
More file actions
60 lines (42 loc) · 1.26 KB
/
Copy pathentrust.py
File metadata and controls
60 lines (42 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def checkPin(pinChecked) -> bool:
"""
Check if the provided PIN is valid.
A valid PIN is defined as a string of exactly 4 digits.
Args:
pinChecked (str): The PIN to be checked."""
if len(pinChecked) != 4 :
return False
pinChecked = str(pinChecked)
sameNum = 0
sequentialNum = 0
prevNum = -2
for x in pinChecked:
x = int(x)
if x not in [0,1,2,3,4,5,6,7,8,9]:
return False
if x == prevNum + 1 or x == prevNum -1:
sequentialNum += 1
else:
sequentialNum = 0
if x == prevNum:
sameNum += 1
else:
sameNum = 0
if sameNum == 3 or sequentialNum == 4:
return False
prevNum = x
return True
print(checkPin("4444")) #ok
# - Must be 4 characters in length.
# - Must contain only digits 0-9.
# - Digit cannot be used three or more times in succession.
# - 4441 is invalid
# - 4404 is valid
# - PINs cannot be uniformly increasing or decreasing by 1
# - 1234 is invalid
# - 9876 is invalid
# - 1357 is valid
# - 1232 is valid
print(checkPin("4424")) #ok
print(checkPin("4321"))
print(checkPin("1232"))