Сколько существует чисел, восьмеричная запись которых содержит
Приведём решение на языке Python.
import itertools
alphabet = "01234567"
cet = "0246"
necet = "1357"
ar = itertools.permutations(alphabet, 5)
arl = []
for e in ar:
arl.append(list(e))
count = 0
for e in arl:
flag = True
for i in range(len(e)-1):
if (e[i] in cet and e[i+1] in cet) or (e[i] in necet and e[i+1] in necet) or e[0] == '0' or e.count('1') != 0:
flag = False
if flag:
count += 1
print(count)
Приведём решение Максима Фатихова на языке Python.
from itertools import *
word = '0234567'
count = 0
for i in permutations(word,5):
x = ''.join(i)
if x[0] != '0':
x = x.replace('7','1').replace('5','1').replace('3','1').replace('6','0').replace('4','0').replace('2','0')
if ('00' not in x) and ('11' not in x):
count += 1
print(count)
Приведём решение Степана Чепурко на языке Python.
from itertools import*
s = permutations('01234567',5)
cnt = 0
for i in s:
p=''.join(i)
if p[0]!='0' and p.count('1')==0:
if int(p[0])%2 != int(p[1])%2 and int(p[1])%2 != int(p[2])%2 and int(p[2])%2 != int(p[3])%2 and int(p[3])%2 != int(p[4])%2:
cnt += 1
print(cnt)
Приведём решение Даны Артюхиной на языке Python.
cnt = 0
for i in range(1, 100000):
i = str(oct(i)[2:])
if len(i) == 5 and '1' not in i:
p = [int(d) for d in i]
if len(set(p)) == 5:
if all(p[i]%2 != p[i+1]%2 for i in range(4)):
cnt += 1
print(cnt)
Ответ: 180.
Приведём решение Сергея Донец на языке PascalABC.NET.
begin
'01234567'.Permutations(5) // 8-ричная 5-значных
.Where(s->s[1] <> '0') // Первой цифрой не может быть 0
.Where(s->'1' not in s) //не содержит цифру 1
.Where(s->not s.IsMatch('[0246][0246]')) //не две чётные цифры рядом
.Where(s->not s.IsMatch('[1357][1357]')) //не две нечётные цифры рядом
.Count.Print;//180
end.

