Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 26th, 2011  |  syntax: Python  |  size: 0.74 KB  |  views: 541  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()
clone this paste RAW Paste Data