Newbie: Python & ADFGVX Cipher Cracking?
Arthur Rambo
arambo314 at hotmail.com
Thu Nov 18 12:53:28 EST 2004
The following solution is far better (based on a generator):
def xpermutations(objects):
"""A generator that returns the complete set of permutations of a
list of objects"""
if objects==[]: yield []
else:
l=len(objects)
for i in xrange(l):
for cc in xpermutations(objects[:i]+objects[i+1:]):
yield [objects[i]]+cc
>>> for p in xpermutations(['A','B','C']):
... print p
...
['A', 'B', 'C']
['A', 'C', 'B']
['B', 'A', 'C']
['B', 'C', 'A']
['C', 'A', 'B']
['C', 'B', 'A']
Derived from Python cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465
Arthur
More information about the Python-list
mailing list