lesson 3,4

This commit is contained in:
vitaliy 2025-10-07 11:04:10 +03:00
parent 97aba26e92
commit 8ce58831aa
4 changed files with 33 additions and 0 deletions

33
guess.py Normal file
View File

@ -0,0 +1,33 @@
import itertools
def all_combinations(alphabet, max_length):
"""Генерирует все комбинации длиной от 1 до max_length"""
all_combos = []
for length in range(1, max_length + 1):
combos = itertools.product(alphabet, repeat=length)
all_combos.extend([''.join(combo) for combo in combos])
return all_combos
russian_lower = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
def vectorize(word, combinations):
vector = []
if len(word) == 1:
return None
last = None
for curr in word:
if not last:
last = curr
continue
pair = last + curr
indx = combinations.index(pair)
vector.append(indx)
return vector
word = 'маме'
combinations = all_combinations(russian_lower, 2)
result = vectorize(word, combinations)
print("Все комбинации длиной 1-2:")
print(combinations)
print("Вектор:", result)

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Binary file not shown.