Advertisement
Guest User

Untitled

a guest
May 26th, 2011
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. def generate_permutations(chars = 4) :
  2.  
  3. #modify if in need!
  4.     allowed_chars = [
  5.         '0',
  6.         '1',
  7.     ]
  8.    
  9.     status = []
  10.     for tmp in range(chars) :
  11.         status.append(0)
  12.        
  13.     last_char = len(allowed_chars)
  14.    
  15.     rows = []
  16.     for x in xrange(last_char ** chars) :
  17.         rows.append("")
  18.         for y in range(chars - 1 , -1, -1) :
  19.             key = status[y]
  20.             rows[x] = allowed_chars[key] + rows[x]
  21.            
  22.         for pos in range(chars - 1, -1, -1) :
  23.             if(status[pos] == last_char - 1) :
  24.                 status[pos] = 0
  25.             else :
  26.                 status[pos] += 1
  27.                 break;
  28.        
  29.     return rows
  30.  
  31. import sys
  32.  
  33.  
  34. print generate_permutations()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement