File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ def subset (arr ):
2
+ output = [[]]
3
+ window = 1
4
+ while window < len (arr ):
5
+ window_start = 0
6
+ while window_start < len (arr ):
7
+ counter = 1
8
+ window_end = window_start + window
9
+ while window_end + counter <= len (arr ):
10
+ to_append = []
11
+ to_append .extend (arr [window_start :window_end ])
12
+ to_append .append (arr [window_end + counter - 1 ])
13
+ output .append (to_append )
14
+ counter += 1
15
+ window_start += 1
16
+ window += 1
17
+ return output
18
+
19
+ def subset_with_recursion (arr ):
20
+ return return_subset_with_recursion (arr , 0 )
21
+
22
+ def return_subset_with_recursion (arr , index ):
23
+ if index >= len (arr ):
24
+ return [[]]
25
+ output = list ()
26
+ small_output = return_subset_with_recursion (arr , index + 1 )
27
+ for element in small_output :
28
+ output .append (element )
29
+ for element in small_output :
30
+ curr = list ()
31
+ curr .append (arr [index ])
32
+ curr .extend (element )
33
+ output .append (curr )
34
+
35
+ return output
36
+
37
+
38
+ print (subset_with_recursion ([9 ,15 ,12 ]))
You can’t perform that action at this time.
0 commit comments