Слайд 3def f(w, x, y, z):
return (not x or y) and (x
or not z) and (x == (not w))
print('w x y z')
for w in 0, 1:
for x in 0, 1:
for y in 0, 1:
for z in 0, 1:
if f(w, x, y, z) == 1:
print(w, x, y, z)
------------------------------------------------------------
w x y z
0 1 1 0
0 1 1 1
1 0 0 0
1 0 1 0
Слайд 5
for n in range(64):
r = [int(bin(n)[2:])]
r += [sum(r) % 2]
r += [sum(r) % 2]
r = [str(i) for i in r]
if int(''.join(r), 2) > 154:
print(n)
break
------------------------------------------------------------
39
Слайд 7for i in range(1, 100):
s = i
n = 2
while
s < 37:
s = s + 3
n = n * 2
if n == 128:
print(i)
# 1 - минимальное
# последнее - максимальное
# Общее количество считается по выводу
------------------------------------------------------------
19
20
21
Слайд 9
from itertools import product
#возможно понадобится permutation (для перестановок )
words = [''.join(i) for
i in list(product("ИГОРЬ", repeat=8))]
k = 0
for word in words:
if word[0] != "Ь" and word.count("О") == 1 and word.count("Ь")==1:
k += 1
print(k)
------------------------------------------------------------
35721
Слайд 11
s = "1" * 101
while s.find("111") >= 0:
s = s.replace("111", "22",
1)
s = s.replace("222", "11", 1)
print(s)
------------------------------------------------------------
112
Слайд 13
num = 81**15 + 3**22 - 27
base = 9
res = ""
while num
> 0:
res = str(num % base) + res
num = num // base
print(res.count("8"))
------------------------------------------------------------
9
Слайд 15
def F(n):
if n == 1:
return 1
if n % 2
== 1:
return n + F(n - 2)
else:
return n * F(n - 1)
print(F(40))
------------------------------------------------------------
16000
Слайд 17
for i in range(1000):
x = i
a = 1
while x
> 0:
a *= x % 7
x = x // 7
if a == 40:
print(i)
break # для наименьшего
------------------------------------------------------------
131