Created
August 11, 2020 17:44
-
-
Save bparanj/61105e064525f0c6603370f9cd027f2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bit_strings(index, array, result) | |
# Base case | |
if index == array.length | |
result << array.dup | |
else | |
# Make a choice to include | |
array[index] = 1 | |
bit_strings(index+1, array, result) | |
# Make a choice to exclude | |
array[index] = 0 | |
bit_strings(index+1, array, result) | |
end | |
end | |
p bit_strings(0, [0,0,0], []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Without dup, you will get same subarrays in the result array.