Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions powerset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

@author: zhengzhang
"""
import time
import matplotlib.pyplot as plt
#import time
#import matplotlib.pyplot as plt

# timing the execution of a function
def timeit(f, *args):
Expand All @@ -27,15 +27,15 @@ def powerset_add(l):
pass
# your code ends here
return pset

# play with the code below in the console, e.g get_bin_str(3, 5)
def get_bin_str(n, up_to):
code = bin(n).split('b')[-1]
if len(code) > up_to:
raise ValueError('not enough')
code = '0' * (up_to - len(code)) + code
return code

def powerset_comb(l):
pset = []
total_items = len(l)
Expand All @@ -48,16 +48,16 @@ def powerset_comb(l):
# your code ends here
pset.append(subset)
return pset

def main():

num_items = 4
my_list = list(range(num_items))

# test using inductive logic
my_pset = powerset_add(my_list)
print("using induction:\n", my_pset)

# test using combinational logic
my_pset = powerset_comb(my_list)
print("using combination:\n", my_pset)
Expand All @@ -69,9 +69,9 @@ def main():
takes = timeit(powerset_comb, my_list)
exec_time.append(takes)

print("powerset", exec_time)
print("powerset", exec_time)
# once you are done with powerset function, uncomment the line below
# and plot the execution time
plt.plot(exec_time)

main()
main()