document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. def wirth(n):
  2.  
  3.     a=1
  4.     b=2
  5.     c=3
  6.     chars = [a,b,c]
  7.     validseq = []
  8.     allseq = [[a],[b],[c]]
  9.  
  10.     i=0
  11.     while i < n-1: ##build all combinations of the 3 characters
  12.         newseq = []
  13.         for e in allseq:
  14.             x = e+[a]
  15.             newseq.append(x)
  16.             y = e+[b]
  17.             newseq.append(y)
  18.             z = e+[c]
  19.             newseq.append(z)
  20.         allseq = newseq
  21.         i+=1
  22.        
  23.     for e in allseq:
  24.         testresult = testvalidity(e,n)
  25.         if testresult:
  26.             validseq.append(testresult)
  27.  
  28.     print validseq
  29.        
  30.  
  31. def testvalidity(e, n):
  32.     i=1
  33.     while i < n:    
  34.         j=0
  35.         while j < min(i, n-i):            
  36.             if e[(i-1)-j:i] == e[i:i+j+1]:                
  37.                 return None
  38.             j += 1
  39.         i += 1
  40.     return e
');