Ярослав составляет коды из букв, входящих в слово ЯРОСЛАВ. Код должен состоять из
Решение. Приведём решение на языке Python.
s = 'ЯРОСЛАВ'
count = 0
for a in s:
for b in s:
for c in s:
for d in s:
for e in s:
s1 = a + b + c + d + e
if s1.count('Я') <= 1 and s1.count('Р') <= 1 and s1.count('О') <= 1 and \
s1.count('С') <= 1 and s1.count('Л') <= 1 and s1.count('А') <= 1 and \
s1.count('В') <= 1 and \
s1.count('Р') + s1.count('С') + s1.count('Л') + s1.count('В') > s1.count('Я') + s1.count('О') + s1.count('А') and \
s1.count('ЯО') == 0 and s1.count('ЯА') == 0 and s1.count('ОА') == 0 and s1.count('ОЯ') == 0 and s1.count('АЯ') == 0 and s1.count('АО') == 0:
count += 1
print(count)
Ответ: 1224.
Приведём решение Масис Давояна на языке Python.
from itertools import *
counter = 0
for perm in permutations('ЯРОСЛАВ', 5):
word = ''.join(perm)
if ((word.count('Р') + word.count('С') + word.count('Л') + word.count('В')) > \
(word.count('Я') + word.count('О') + word.count('А'))) and (word.count('ЯО') == 0 and \
word.count('ОЯ') == 0 and word.count('ЯА') == 0 and word.count('АЯ') == 0 and \
word.count('ОА') == 0 and word.count('АО') == 0):
counter += 1
print(counter)
Приведём решение Ильи Андрианова на языке Python.
from itertools import permutations
count = 0
for var in permutations('ЯРОСЛАВ', 5):
slovo = ''.join(var)
sogl = [x for x in slovo if x in 'РСЛВ']
glas = [x for x in slovo if x in 'ЯОА']
if len(sogl) > len(glas):
slovo = slovo.replace('Я', 'А').replace('О', 'А')
if 'АА' not in slovo:
count += 1
print(count)
Примечание 8 и 9 строки программы возможно заменить на if all(pair not in slovo for pair in 'ЯА АЯ ЯО ОЯ АО ОА'.split()):
Приведём решение Андрея Брусиловского на языке Python.
from itertools import permutations
count = 0
for i in permutations ('ЯРОСЛАВ',r=5):
s =''.join(i)
s = s.replace('Я','А').replace('О','А')
s = s.replace('Р', 'В').replace('С', 'В').replace('Л', 'В')
if s.count('В')>s.count('А') and not 'АА' in s:
count += 1
print(count)
Приведём решение Михаила Глинского на языке Python.
al = 'ЯРОСЛАВ'
k = 0
for b1 in al:
for b2 in al:
for b3 in al:
for b4 in al:
for b5 in al:
s=b1+b2+b3+b4+b5
if len(set(s))==5:
s = s.replace('Я','*').replace('О','*').replace('А','*')
if s.count('*')<3 and s.count('**')==0:
k += 1
print(k)
Приведём решение Юрия Красильникова на языке Python.
from itertools import permutations
k=0
for p in permutations('ЯРОСЛАВ',5):
t=''.join([('Г' if c in 'ЯОА' else 'С') for c in p])
if t.count('С')>t.count('Г') and not 'ГГ' in t: k+=1
print(k)
PDF-версии: 