@@ -56,104 +56,3 @@ def stirling(n, k, skip_calculation=False):
5656def abs_stirling (n , k ):
5757 return abs (stirling (n , k ))
5858
59- ###############################################################################
60-
61- _length_of_recurrent_perm_space_cache = {}
62-
63- def calculate_length_of_recurrent_perm_space (k , ftt ):
64- from python_toolbox import nifty_collections
65- from python_toolbox import cute_iter_tools
66- cache = _length_of_recurrent_perm_space_cache
67- if not isinstance (ftt , nifty_collections .FrozenTallyTally ):
68- ftt = nifty_collections .FrozenTallyTally (ftt )
69- if k == 0 :
70- return 1
71- elif k == 1 :
72- assert ftt
73- # (Works because `FrozenCrateCounter` has a functioning `__bool__`,
74- # unlike Python's `Counter`.)
75- return ftt .n_elements
76- try :
77- return cache [(k , ftt )]
78- except KeyError :
79- pass
80-
81- levels = []
82- current_ftts = {ftt }
83- while len (levels ) < k and current_ftts :
84- k_ = k - len (levels )
85- levels .append (
86- {ftt_ : ftt_ .get_sub_ftts_for_one_crate_removed ()
87- for ftt_ in current_ftts
88- if (k_ , ftt_ ) not in cache }
89- )
90- current_ftts = set (itertools .chain (* levels [- 1 ].values ()))
91-
92- # The last level is calculated. Time to make our way up.
93- for k_ , level in enumerate (reversed (levels ), (k - len (levels ) + 1 )):
94- if k_ == 1 :
95- for ftt_ , sub_ftt_tally in level .items ():
96- cache [(k_ , ftt_ )] = ftt_ .n_elements
97- else :
98- for ftt_ , sub_ftt_tally in level .items ():
99- cache [(k_ , ftt_ )] = sum (
100- (cache [(k_ - 1 , sub_ftt )] * factor for
101- sub_ftt , factor in sub_ftt_tally .items ())
102- )
103-
104- return cache [(k , ftt )]
105-
106-
107-
108-
109- ###############################################################################
110-
111- _length_of_recurrent_comb_space_cache = {}
112-
113- def calculate_length_of_recurrent_comb_space (k , ftt ):
114- '''
115- blocktodo gotta properly name these two sons of bitches
116- '''
117- from python_toolbox import nifty_collections
118- from python_toolbox import cute_iter_tools
119- cache = _length_of_recurrent_comb_space_cache
120- if not isinstance (ftt , nifty_collections .FrozenTallyTally ):
121- ftt = nifty_collections .FrozenTallyTally (ftt )
122- if k == 0 :
123- return 1
124- elif k == 1 :
125- assert ftt
126- # (Works because `FrozenCrateCounter` has a functioning `__bool__`,
127- # unlike Python's `Counter`.)
128- return ftt .n_elements
129- try :
130- return cache [(k , ftt )]
131- except KeyError :
132- pass
133-
134- levels = []
135- current_ftts = {ftt }
136- while len (levels ) < k and current_ftts :
137- k_ = k - len (levels )
138- levels .append (
139- {ftt_ : ftt_ .get_sub_ftts_for_one_crate_and_previous_piles_removed ()
140- for ftt_ in current_ftts
141- if (k_ , ftt_ ) not in cache }
142- )
143- current_ftts = set (itertools .chain (* levels [- 1 ].values ()))
144-
145- # The last level is calculated. Time to make our way up.
146- for k_ , level in enumerate (reversed (levels ), (k - len (levels ) + 1 )):
147- if k_ == 1 :
148- for ftt_ , sub_ftts in level .items ():
149- cache [(k_ , ftt_ )] = len (sub_ftts )
150- else :
151- for ftt_ , sub_ftts in level .items ():
152- cache [(k_ , ftt_ )] = sum (
153- (cache [(k_ - 1 , sub_ftt )] for sub_ftt in sub_ftts )
154- )
155-
156- return cache [(k , ftt )]
157-
158-
159-
0 commit comments