From 07512b4dbd3c68956df0b3fba80e5c19e34d253f Mon Sep 17 00:00:00 2001 From: Tav-1 Date: Tue, 7 Mar 2017 13:52:07 +0800 Subject: [PATCH] My Changes --- powerset.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/powerset.py b/powerset.py index 1082f65..15bbba8 100644 --- a/powerset.py +++ b/powerset.py @@ -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): @@ -27,7 +27,7 @@ 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] @@ -35,7 +35,7 @@ def get_bin_str(n, up_to): raise ValueError('not enough') code = '0' * (up_to - len(code)) + code return code - + def powerset_comb(l): pset = [] total_items = len(l) @@ -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) @@ -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() \ No newline at end of file +main()