-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslideshow.py
More file actions
109 lines (86 loc) · 2.95 KB
/
slideshow.py
File metadata and controls
109 lines (86 loc) · 2.95 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from helpers import *
listOfInputs = open('a_example.txt', 'r').read().splitlines()
photosNumber = int(listOfInputs[0])
photosList = []
for i in range(photosNumber):
photo = listOfInputs[i+1].split()
photosList.append({
'id': i,
'direction': photo[0],
'tags': photo[2:]
})
# Separating photos into V list and H list
vPhotos = []
hPhotos = []
for i in range(photosNumber):
if(photosList[i]['direction'] == 'H'):
hPhotos.append(photosList[i])
else:
vPhotos.append(photosList[i])
# Filling slidesList
slidesList = hPhotos[:]
for i in range(0, len(vPhotos)):
if(i+1 > len(vPhotos)):
continue
minSim = Get_Similarity(vPhotos[i], vPhotos[i+1])
bestCompanionPhoto = vPhotos[i+1]
bestCompanionPhotoIndex = i+1
if(len(vPhotos) <= 2):
slidesList.append({
'id': str(vPhotos[i]['id']) + ' ' + str(bestCompanionPhoto['id']),
'direction': 'V',
'tags': list(dict.fromkeys(vPhotos[i]['tags']+bestCompanionPhoto['tags']))
}
)
break
for j in range(0, len(vPhotos)):
currentSim = Get_Similarity(vPhotos[i], vPhotos[j])
if (currentSim < minSim):
minSim = currentSim
bestCompanionPhoto = vPhotos[j]
bestCompanionPhotoIndex = j
flag = True
slidesList.append({
'id': str(vPhotos[i]['id']) + ' ' + str(bestCompanionPhoto['id']),
'direction': 'V',
'tags': list(dict.fromkeys(vPhotos[i]['tags']+bestCompanionPhoto['tags']))
})
vPhotos = list(filter(lambda x: x['id'] != vPhotos[i]['id']
and x['id'] != bestCompanionPhoto['id'], vPhotos))
def diff_similarity_diff(list1, list2):
count = 0
for i in list1:
if i in list2:
count = count + 1
return (len(list1) - count), count, (len(list2) - count)
def Order_slides(L):
orderedList = []
for i in range(0, len(L)):
if L[i] not in orderedList:
orderedList.append(L[i])
score = 0
index = 0
flag1 = 0
flag2 = 0
for j in range(i+1, len(L)):
flag1 = 1
diff1, common, diff2 = diff_similarity_diff(
L[i]["tags"], L[j]["tags"])
Min = min(diff1, common, diff2)
if(Min > score):
flag2 = 1
score = Min
index = j
if flag1 == 1 and flag2 == 1:
if L[index] not in orderedList:
orderedList.append(L[index])
#del L[index]
elif flag1 == 1 and flag2 == 0:
if L[index] not in orderedList:
orderedList.append(L[i+1])
#del L[index]
return orderedList
fileresult = open('a_example_ans.txt', 'w')
print(len(Order_slides(slidesList)), file=fileresult)
for i in Order_slides(slidesList):
print(i['id'], file=fileresult)