Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def Subset n
  2.  
  3. arr = [0]*n
  4.  
  5. begin
  6.  
  7. arr[n-1] += 1
  8.  
  9. for i in (n-1).downto(1)
  10.  
  11. if arr[i] > 1 then
  12.  
  13. arr[ i ] -= 2
  14.  
  15. arr[i - 1] += 1
  16. end
  17.  
  18. end
  19.  
  20. for i in 0..n-1
  21.  
  22. if arr[i] != 0 then
  23.  
  24. print (i+1)
  25.  
  26. end
  27. end
  28.  
  29. s = 0
  30.  
  31. for i in 0..n-1
  32.  
  33. if arr[i] then
  34.  
  35. s += arr[i]
  36.  
  37. end
  38. end
  39.  
  40. print "\n"
  41.  
  42. end while s < n
  43.  
  44. end
  45.  
  46. Subset 5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement