Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tsmsogn/2e098d235a2fb87340ff to your computer and use it in GitHub Desktop.
Save tsmsogn/2e098d235a2fb87340ff to your computer and use it in GitHub Desktop.
p = 4
for i in 0...(1 << p)
stack = Array.new(p, 0)
for j in 0...p
stack[j] = 1 if i >> j & 1 != 0
end
puts stack.join
end
# 0000
# 1000
# 0100
# 1100
# 0010
# 1010
# 0110
# 1110
# 0001
# 1001
# 0101
# 1101
# 0011
# 1011
# 0111
# 1111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment