fork download
  1. # your code goes here
  2. b = []
  3. a = [0]*100
  4.  
  5. def bin_to_int(x):
  6. j = len(x) - 1
  7. sum = 0
  8. for i in x:
  9. if i == 1:
  10. sum += pow(2, j)
  11. j = j - 1
  12. else:
  13. j -= 1
  14. return sum
  15.  
  16. def permutation(i, x):
  17. if i >= x:
  18. b.append(a[0:x])
  19. return
  20. if a[i-1] == 1 or a[i-1] == 0:
  21. a[i] = 0
  22. permutation(i+1, x)
  23. if a[i-1] == 0:
  24. a[i] = 1
  25. permutation(i+1, x);
  26.  
  27. a[0] = 1
  28. permutation(0, 4)
  29. dict = {}
  30. for i in b:
  31. key = bin_to_int(i)
  32. if key not in dict.keys():
  33. dict[key] = key
  34. print dict.values()
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
[0, 1, 2, 4, 5, 8, 9, 10]