Created
September 29, 2019 19:51
-
-
Save abhinavjonnada82/580df08163f6cb97ddbfe149365ccf60 to your computer and use it in GitHub Desktop.
This file contains 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
# Finonacci | |
def getNthFib(n): | |
if n == 1: | |
return 0 | |
if n == 2: | |
return 1 | |
else: | |
return getNthFib(n-1) + getNthFib(n-2) | |
# Powerset | |
# Run a loop till length of the given list. | |
# Run a loop from i+1 to length of the list to get all the subarrays from i to its right. | |
def powerset(array): | |
subsets = [[]] | |
for i in range(0, len(array) + 1): | |
for j in range (i+1, len(array) + 1): | |
currentSubset = array[i:j] | |
subsets.append(currentSubset) | |
return subsets | |
array = [1,2] | |
print(powerset(array)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment