Skip to content

Commit 1bf57f4

Browse files
committed
-
1 parent 6ced46e commit 1bf57f4

File tree

3 files changed

+54
-21
lines changed

3 files changed

+54
-21
lines changed

source_py3/python_toolbox/combi/perm_space.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ class O: length = 0
638638
break
639639
else:
640640
wip_i -= candidate_sub_perm_space.length
641-
shit_set.add(wip_perm_sequence_dict[j])
641+
if self.is_combination:
642+
shit_set.add(wip_perm_sequence_dict[j])
642643
del wip_perm_sequence_dict[j]
643644
else:
644645
raise RuntimeError
@@ -782,29 +783,59 @@ def index(self, perm):
782783
wip_perm_number = 0
783784
unused_values = list(self.sequence)
784785
perm_sequence_list = list(perm._perm_sequence)
786+
shit_set = set()
785787
for i, value in enumerate(perm):
786788
if i in self.fixed_map:
787789
if self.fixed_map[i] == value:
788790
unused_values.remove(value)
789791
continue
790792
else:
791793
raise ValueError
792-
lower_values = [thing for thing in
793-
nifty_collections.OrderedSet(unused_values)
794-
if unused_values.index(thing) <
795-
unused_values.index(value)]
794+
lower_values = [
795+
thing for thing in
796+
nifty_collections.OrderedSet(unused_values) if
797+
unused_values.index(thing) < unused_values.index(value) and
798+
thing not in shit_set
799+
]
796800
unused_values.remove(value)
797801
for lower_value in lower_values:
798802
temp_fixed_map = dict(
799803
enumerate(perm_sequence_list[:i] + [lower_value])
800804
)
801805
temp_fixed_map.update(self.fixed_map)
802-
wip_perm_number += PermSpace(
803-
self.sequence,
804-
fixed_map=temp_fixed_map,
805-
n_elements=self.n_elements,
806-
is_combination=self.is_combination
807-
).length
806+
807+
808+
head = []
809+
n_elements_to_use = self.n_elements
810+
for k in sequence_tools.CuteRange(infinity):
811+
try:
812+
head.append(temp_fixed_map[k])
813+
except KeyError:
814+
break
815+
else:
816+
del temp_fixed_map[k]
817+
n_elements_to_use -= 1
818+
sequence_to_use = list(self.sequence)
819+
for item in head:
820+
if self.is_combination:
821+
sequence_to_use = sequence_to_use[
822+
sequence_to_use.index(item) + 1:
823+
]
824+
else:
825+
sequence_to_use.remove(item)
826+
827+
sequence_to_use = [x for x in sequence_to_use if x not in shit_set]
828+
829+
if len(sequence_to_use) >= n_elements_to_use:
830+
wip_perm_number += PermSpace(
831+
sequence_to_use,
832+
fixed_map=temp_fixed_map,
833+
n_elements=n_elements_to_use,
834+
is_combination=self.is_combination
835+
).length
836+
if self.is_combination:
837+
shit_set.add(lower_value)
838+
808839

809840
perm_number = wip_perm_number
810841

source_py3/python_toolbox/math_tools/sequences.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ def catshit(k, recurrence_counter):
122122
if not isinstance(recurrence_counter, nifty_collections.FrozenCounterCounter):
123123
recurrence_counter = \
124124
nifty_collections.FrozenCounterCounter(recurrence_counter)
125-
if k == 1:
125+
if k == 0:
126+
return 1
127+
elif k == 1:
126128
assert recurrence_counter
127129
# (Works because `FrozenCrateCounter` has a functioning `__bool__`,
128130
# unlike Python's `Counter`.)

source_py3/test_python_toolbox/test_combi/test_exhaustive.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ def _check_variation_selection(variation_selection):
118118
# Can't even test this illogical clash.
119119
return
120120

121-
#blocktodo remove
122-
if not (variation_selection.is_recurrent and variation_selection.is_combination):
123-
return
124-
#blocktodo remove
125-
if variation_selection.number != 240:
126-
return
121+
# #blocktodo remove
122+
# if not (variation_selection.is_recurrent and variation_selection.is_combination):
123+
# return
124+
# #blocktodo remove
125+
# if variation_selection.number != 192:
126+
# return
127127

128128
iterable_or_length = (
129129
'abracab' if variation_selection.is_recurrent else
@@ -195,9 +195,9 @@ def _check_variation_selection(variation_selection):
195195

196196
assert perm_space.length == len(brute_perm_space_tuple)
197197

198-
#blocktodo remove
199-
tuple(perm_space)
200-
198+
if perm_space.length:
199+
assert tuple(perm_space[-1]) == brute_perm_space_tuple[-1]
200+
201201
if perm_space.length >= 2:
202202
assert perm_space.index(perm_space[-1]) > \
203203
perm_space.index(perm_space[0])

0 commit comments

Comments
 (0)