Код: Выделить всё
def combination_sort(iterable):
def sort_formula(iterable):
return iterable
return sorted(iterable, key=sort_formula)
def combination_to_index(combination, iterable):
# Use the formula on the iterable
# Take the new iterale and get order
base = len(iterable)
index = 0
for char in combination:
index = index * base + iterable.index(char)
return index
# Example iterable - here I'm assuming you want '0123456789abcdef'
iterable = combination_sort('0123456789abcdefg')
# Define the target combination (lowercased and prefixed with '0x')
target_combination = ('0000000000000000000000032100000000000000'.lower())
# Calculate the position (index) of the target combination
target_index = combination_to_index(target_combination, iterable)
print(f"Index of target combination: {target_index}")
Я не хочу просто помещать строку 6813Eb9362372EEF6200f3b1 dbC3f819671cBA6g в list и укажите код, чтобы начать с него. Мне нужна формула, которая сможет вычислить порядок и поместить туда комбинации.
Подробнее здесь: https://stackoverflow.com/questions/790 ... dex-lookup