|
2 | 2 | # This program is distributed under the MIT license. |
3 | 3 |
|
4 | 4 | import numbers |
| 5 | +import collections |
5 | 6 |
|
6 | 7 |
|
7 | 8 | infinity = float('inf') |
|
11 | 12 | _n_highest_cache_completed = -1 |
12 | 13 | def stirling(n, k, skip_calculation=False): |
13 | 14 | ''' |
14 | | - blocktododoc specify first or second kind |
| 15 | + blocktododoc specify first kind |
15 | 16 | ''' |
16 | 17 | global _n_highest_cache_completed |
17 | 18 | if k not in range(n + 1): |
@@ -55,3 +56,22 @@ def stirling(n, k, skip_calculation=False): |
55 | 56 | def abs_stirling(n, k): |
56 | 57 | return abs(stirling(n, k)) |
57 | 58 |
|
| 59 | +############################################################################### |
| 60 | + |
| 61 | +_shitfuck_cache = {} |
| 62 | + |
| 63 | +def shitfuck(k, recurrences): |
| 64 | + 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) |
| 68 | + 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 |
| 73 | + levels.append(new_level) |
| 74 | + # The last level is calculated. Time to make our way up. |
| 75 | + if len(levels) == k: |
| 76 | + |
| 77 | + |
0 commit comments