Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created March 25, 2017 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/4abe5afe080bc0b52e10114335ded576 to your computer and use it in GitHub Desktop.
Save thinkphp/4abe5afe080bc0b52e10114335ded576 to your computer and use it in GitHub Desktop.
def Subset n
arr = [0]*n
begin
arr[n-1] += 1
for i in (n-1).downto(1)
if arr[i] > 1 then
arr[ i ] -= 2
arr[i - 1] += 1
end
end
for i in 0..n-1
if arr[i] != 0 then
print (i+1)
end
end
s = 0
for i in 0..n-1
if arr[i] then
s += arr[i]
end
end
print "\n"
end while s < n
end
Subset 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment