@@ -60,52 +60,48 @@ def abs_stirling(n, k):
6060
6161_length_of_recurrent_perm_space_cache = {}
6262
63- def calculate_length_of_recurrent_perm_space (k , recurrence_counter ):
63+ def calculate_length_of_recurrent_perm_space (k , ftt ):
6464 from python_toolbox import nifty_collections
6565 from python_toolbox import cute_iter_tools
6666 cache = _length_of_recurrent_perm_space_cache
67- if not isinstance (recurrence_counter , nifty_collections .FrozenTallyTally ):
68- recurrence_counter = \
69- nifty_collections .FrozenTallyTally (recurrence_counter )
67+ if not isinstance (ftt , nifty_collections .FrozenTallyTally ):
68+ ftt = nifty_collections .FrozenTallyTally (ftt )
7069 if k == 0 :
7170 return 1
7271 elif k == 1 :
73- assert recurrence_counter
72+ assert ftt
7473 # (Works because `FrozenCrateCounter` has a functioning `__bool__`,
7574 # unlike Python's `Counter`.)
76- return recurrence_counter .n_elements
75+ return ftt .n_elements
7776 try :
78- return cache [(k , recurrence_counter )]
77+ return cache [(k , ftt )]
7978 except KeyError :
8079 pass
8180
8281 levels = []
83- current_reccurence_counters = {recurrence_counter }
84- while len (levels ) < k and current_reccurence_counters :
82+ current_ftts = {ftt }
83+ while len (levels ) < k and current_ftts :
8584 k_ = k - len (levels )
8685 levels .append (
87- {recurrence_counter_ : recurrence_counter_ .
88- get_sub_counters_for_one_crate_removed ()
89- for recurrence_counter_ in current_reccurence_counters
90- if (k_ , recurrence_counter_ ) not in cache }
86+ {ftt_ : ftt_ .get_sub_ftts_for_one_crate_removed ()
87+ for ftt_ in current_ftts
88+ if (k_ , ftt_ ) not in cache }
9189 )
92- current_reccurence_counters = \
93- set (itertools .chain (* levels [- 1 ].values ()))
90+ current_ftts = set (itertools .chain (* levels [- 1 ].values ()))
9491
9592 # The last level is calculated. Time to make our way up.
9693 for k_ , level in enumerate (reversed (levels ), (k - len (levels ) + 1 )):
9794 if k_ == 1 :
98- for recurrence_counter_ , sub_counters_counter in level .items ():
99- cache [(k_ , recurrence_counter_ )] = \
100- recurrence_counter_ .n_elements
95+ for ftt_ , sub_ftt_tally in level .items ():
96+ cache [(k_ , ftt_ )] = ftt_ .n_elements
10197 else :
102- for recurrence_counter_ , sub_counters_counter in level .items ():
103- cache [(k_ , recurrence_counter_ )] = sum (
104- (cache [(k_ - 1 , sub_counter )] * factor for
105- sub_counter , factor in sub_counters_counter .items ())
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 ())
106102 )
107103
108- return cache [(k , recurrence_counter )]
104+ return cache [(k , ftt )]
109105
110106
111107
@@ -114,54 +110,50 @@ def calculate_length_of_recurrent_perm_space(k, recurrence_counter):
114110
115111_length_of_recurrent_comb_space_cache = {}
116112
117- def calculate_length_of_recurrent_comb_space (k , recurrence_counter ):
113+ def calculate_length_of_recurrent_comb_space (k , ftt ):
118114 '''
119115 blocktodo gotta properly name these two sons of bitches
120116 '''
121117 from python_toolbox import nifty_collections
122118 from python_toolbox import cute_iter_tools
123119 cache = _length_of_recurrent_comb_space_cache
124- if not isinstance (recurrence_counter , nifty_collections .FrozenTallyTally ):
125- recurrence_counter = \
126- nifty_collections .FrozenTallyTally (recurrence_counter )
120+ if not isinstance (ftt , nifty_collections .FrozenTallyTally ):
121+ ftt = nifty_collections .FrozenTallyTally (ftt )
127122 if k == 0 :
128123 return 1
129124 elif k == 1 :
130- assert recurrence_counter
125+ assert ftt
131126 # (Works because `FrozenCrateCounter` has a functioning `__bool__`,
132127 # unlike Python's `Counter`.)
133- return recurrence_counter .n_elements
128+ return ftt .n_elements
134129 try :
135- return cache [(k , recurrence_counter )]
130+ return cache [(k , ftt )]
136131 except KeyError :
137132 pass
138133
139134 levels = []
140- current_reccurence_counters = {recurrence_counter }
141- while len (levels ) < k and current_reccurence_counters :
135+ current_ftts = {ftt }
136+ while len (levels ) < k and current_ftts :
142137 k_ = k - len (levels )
143138 levels .append (
144- {recurrence_counter_ : recurrence_counter_ .
145- get_sub_counters_for_one_crate_and_previous_piles_removed ()
146- for recurrence_counter_ in current_reccurence_counters
147- if (k_ , recurrence_counter_ ) not in cache }
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 }
148142 )
149- current_reccurence_counters = \
150- set (itertools .chain (* levels [- 1 ].values ()))
143+ current_ftts = set (itertools .chain (* levels [- 1 ].values ()))
151144
152145 # The last level is calculated. Time to make our way up.
153146 for k_ , level in enumerate (reversed (levels ), (k - len (levels ) + 1 )):
154147 if k_ == 1 :
155- for recurrence_counter_ , sub_counters in level .items ():
156- cache [(k_ , recurrence_counter_ )] = len (sub_counters )
148+ for ftt_ , sub_ftts in level .items ():
149+ cache [(k_ , ftt_ )] = len (sub_ftts )
157150 else :
158- for recurrence_counter_ , sub_counters in level .items ():
159- cache [(k_ , recurrence_counter_ )] = sum (
160- (cache [(k_ - 1 , sub_counter )] for
161- sub_counter in sub_counters )
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 )
162154 )
163155
164- return cache [(k , recurrence_counter )]
156+ return cache [(k , ftt )]
165157
166158
167159
0 commit comments