Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by bitch ( 7 years ago )
import re #for regex

f = open('e_shiny_selfies.txt','r')
f1 = f.readlines()

vert = []
slides = []
picId = 0
numOfSlides = 0


class Slides:

    def __init__(self,type,str1,str2=None):
        self.index = []
        self.numOfTags = 0
        self.tags = set()

        #Vertical
        if(type=="V"):

            self.data1 = str1.split(" ")
            self.data2 = str2.split(" ")

            
            if(int(self.data1[1])>1 and int(self.data2[1])>1):
                self.tags = set(self.data1[2:len(self.data1)-1]) | set(self.data2[2:len(self.data1)-1])
            elif(int(self.data1[1])==1 and int(self.data2[1])>1):
                self.tags = {self.data1[2]}
                self.tags = self.tags | set(self.data2[2:len(self.data1)-1])
            elif(int(self.data2[1])==1 and int(self.data1[1])>1):
                self.tags = {self.data2[2]}
                self.tags = self.tags | set(self.data1[2:len(self.data1)-1])
            else:
                self.tags = {self.data1[2]}
                temp = {self.data2[2]}
                self.tags = self.tags.union(temp)
            
            self.numOfTags = len(self.tags)

            self.index.append(self.data1[-1])
            self.index.append(self.data2[-1])
        

        #Horizontal
        elif(type=="H"):

            self.data1 = str1.split(" ")
            self.index.append(self.data1[-1])

            if(int(self.data1[1])>1):
                self.tags = set(self.data1[2:len(self.data1)-1])
            else:
                self.tags = {self.data1[2]}

            self.numOfTags = len(self.tags)
    
    #Print object
    def __repr__(self):
        if len(self.index)==1:
            string = "%s" % (self.index[0])
        else:
            string = "%s   %s" % (self.index[0],self.index[1])

        # for i in self.tags:
        #     string += "%s " % (i)
        return string





for x in f1:

    if re.search("^V", x):
        vert.append(x.replace('\n', '')+" "+str(picId))
        picId += 1
        numOfSlides += 1
    elif re.search("^H", x):
        slides.append(Slides("H",x.replace('\n', '')+" "+str(picId)))
        picId += 1
    else:
        numOfPics = int(x)

    if len(vert)==2:
        slides.append(Slides("V",str(vert[0]),str(vert[1])))
        vert=[]
        numOfSlides += 1



def interestFactor(ob1, ob2):
    ob_intr = len(ob1.tags.intersection(ob2.tags))
    ob1only = len(ob1.tags.difference(ob2.tags))
    ob2only = len(ob2.tags.difference(ob1.tags))
    return min(ob1only,ob2only,ob_intr)


for i in slides:
    print(i)

for i in range(0,numOfSlides-1):
    iof = interestFactor(slides[i],slides[i+1])
    if i+2 < numOfSlides:
        for j in range(i+2,numOfSlides):
            if(interestFactor(slides[i],slides[j])>iof) :
                iof = interestFactor(slides[i],slides[j])
                slides[i+1],slides[j]=slides[j],slides[i+1]
    else:
        continue

print("\n\n\nnew:\n\n\n")

for i in slides:
    print(i)

 

Revise this Paste

Your Name: Code Language: