-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlgorithm_from_json
73 lines (63 loc) · 1.86 KB
/
Algorithm_from_json
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
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
VOS215 = [1, 2, 13, 15, 16, 19, 28, 78] # list of VOS 215
# list of IoT and YOTA
IoT_YOTA = [251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271]
#getting the values from json
with open("file.json", "r") as f:
dic = json.load(f)
branch1 = dic["branch1"]
branch2 = dic["branch2"]
VOS1: list = dic["set1"]
VOS2: list = dic["set2"]
# functions for excepting: VOS215, IoT_YOTA and 238/228
def for_215(x):
for z in x:
if z == 215:
return True
return False
def search_in_215(x):
for y in x:
if y in VOS215:
return True
return False
def search_in_yota_and_iot(x):
for y in x:
if y in IoT_YOTA:
return True
return False
def for_228_and_238(x):
for tt in x:
if (tt == 228) or (tt == 238):
return True
return False
# Algorithm
if branch1 == branch2:
print('permitted')
elif (branch1 != branch2) and (not VOS1 or not VOS2):
print('Not announced')
else:
for i in VOS1:
if i in VOS2:
print('permitted')
break
elif (i not in VOS2) and (i in VOS215):
if for_215(VOS2):
print('permitted')
elif search_in_yota_and_iot(VOS2):
print('permitted')
else:
print('denied')
elif (i not in VOS2) and (i == 215):
if search_in_215(VOS2):
print('permitted')
elif search_in_yota_and_iot(VOS2):
print('permitted')
else:
print('denied')
else:
if search_in_yota_and_iot(VOS1) or search_in_yota_and_iot(VOS2):
print('permitted')
elif for_228_and_238(VOS1) and for_228_and_238(VOS2):
print('permitted')
else:
print('denied')