Skip to content

Commit 5765c2c

Browse files
committed
-
1 parent 6d252ec commit 5765c2c

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

source_py3/python_toolbox/math_tools/sequences.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,27 @@ def abs_stirling(n, k):
6060

6161
_shitfuck_cache = {}
6262

63-
def shitfuck(k, recurrences):
63+
def get_sub_counters(counter):
64+
assert isinstance(counter, nifty_collections.FrozenCounter)
65+
return {
66+
nifty_collections.FrozenCounter(
67+
{key: (value - (key == key_to_reduce)) for key, value in self.items()}
68+
) for key_to_reduce in self
69+
}
70+
71+
72+
def shitfuck(k, recurrence_counter):
6473
from python_toolbox import nifty_collections
65-
assert isinstance(recurrences, nifty_collections.FrozenCounter)
66-
levels = [collections.Counter({recurrences: 1})]
67-
while len(levels) < k and any(((k - len(levels) + 1), recurrences)
74+
assert isinstance(recurrence_counter, nifty_collections.FrozenCounter)
75+
levels = []
76+
current_reccurence_counters = {recurrence_counter}
77+
while len(levels) < k and any(((k - len(levels) + 1), recurrence_counter)
6878
not in _shitfuck_cache for x in levels[-1]):
69-
new_level = collections.Counter()
70-
for recurrences_, factor in levels[-1].items():
71-
for smaller_recurrences in recurrences_.counters_with_one_removed:
72-
new_level[(k - len(levels), smaller_recurrences)] += factor
79+
new_level = {}
80+
for recurrence_counter_ in current_reccurence_counters:
81+
new_level[recurrence_counter_] =
82+
for smaller_recurrence_counter in recurrence_counter_.counters_with_one_removed:
83+
new_level[(k - len(levels), smaller_recurrence_counter)] += factor
7384
levels.append(new_level)
7485
# The last level is calculated. Time to make our way up.
7586
if len(levels) == k:

source_py3/python_toolbox/nifty_collections/frozen_counter.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,3 @@ def __and__(self, other):
205205
result[element] = new_count
206206
return FrozenCounter(result)
207207

208-
@caching.CachedProperty
209-
@LazyTuple.factory()
210-
def counters_with_one_removed(self):
211-
for key_to_reduce in self.keys():
212-
return type(self)(
213-
{key: (value - (key == key_to_reduce)) for key, value
214-
in self.items()}
215-
)
216-
217-

0 commit comments

Comments
 (0)