class Place: titre = '' dest = [] def __init__(self, ti): self.titre = ti def f(self): return titre def xcomb(items, n): if n==0: yield [] else: for i in xrange(len(items)): for cc in xcomb(items[:i]+items[i+1:],n-1): yield [items[i]]+cc def perm(items, count): return list(xcomb(items, count)) def checkParcour(items): for i in range(0, len(items)-1) : currentobj = items[i] nextobj = items[i+1] if(nextobj not in currentobj.dest) : return False return True def descriptionParcour(items): #print [place.titre for place in items] result = [] for i in range(0, len(items)-1) : currentobj = items[i] nextobj = items[i+1] result.append(currentobj.titre) result.append(currentobj.dest.index(nextobj)+1) print result spawn=Place('spawn (3eme etage)') tank=Place('tank factory') lit=Place('lit') pont=Place('pont armurerie') depo=Place('depot ravitaillement') elec=Place('electricité dragon command') spawn.dest = [pont, lit, elec] tank.dest = [lit, depo, pont] lit.dest = [spawn, tank, elec] pont.dest = [depo, tank, spawn] depo.dest = [elec, pont, tank] elec.dest = [depo, spawn, lit] places = [spawn, tank, lit, pont, depo, elec] #definir depart (vert) et arrivée (cylindre) start = depo end = pont places.remove(start) places.remove(end) greatParcours = [] for combi in perm (places, len(places)) : parcour = combi parcour.insert(0, start) parcour.insert(len(parcour), end) if(checkParcour(parcour) == True) : greatParcours.append(parcour) for p in greatParcours : descriptionParcour(p)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question