Загрузка данных
#1
from itertools import *
tab = '69 357 249 367 28 1489 248 567 136'.split()
pic = 'ab av ag ai bv vk ki kj je ie eg gd dj'.split()
print(*range(1, 10))
for var in permutations('abvgdeijk'):
if all(str(var.index(x) + 1) in tab[var.index(y)] for x, y in pic):
print(*var)
#2
#((z→x)→(x≡y))∨¬w
from itertools import permutations,product
def f(x,y,w,z):
return ((z<=x)<=(x==y))or not(w)
for x1,x2,x3,x4,x5 in product([0,1],repeat=5):
t=(
(x1,0,1,0,0),
(0,x2,x3,0,0),
(x4,1,1,x5,0)
)
if len(t)==len(set(t)):
for p in permutations("xyzw",r=4):
if all(f(**dict(zip(p,line)))==line[-1] for line in t):
print(*p)
#5
def to_12(n):
digits = '0123456789AB'
result = ''
while n > 0:
result = digits[n % 12] + result
n //= 12
return result
#6
from turtle import *
tracer(0)
screensize(10000,10000)
m=40
for _ in range(2):
fd(14*m);lt(270);bk(12*m);rt(90)
up()
fd(9*m);rt(90);bk(7*m);lt(90)
down()
for i in range(2):
fd(13*m);rt(90);fd(6*m);rt(90)
up()
for x in range(0,50):
for y in range(0,50):
goto(x*m,y*m)
dot(3,"blue")
update()
exitonclick()
#7
N=2^i#цвета
V=x*y*i
#8
from itertools import product,permutations
letters = sorted("ВЕСНА")
words= list(product(letters,repeat=4))
cnt=0
for word in words:
otv="".join(word)
cnt+=1
if otv.count("Е")==0 and "АА" not in otv:
break
print(cnt)
#9
for line in open('9.txt'):
a = [int(x) for x in line.split()]
p2 = [x for x in a if a.count(x) == 2]
np = [x for x in a if a.count(x) == 1]
#13
import ipaddress
ip = '95.24.30.144'
mask = '255.255.248.0'
network = ipaddress.ip_network(f'{ip}/{mask}', 0)
highest_ip = list(network.hosts())[-1]#[0]если наименьший
print(f"IP-адрес: {highest_ip}")
#СУММА ОКТЕТОВ
answer_sum = sum(int(x) for x in str(highest_ip).split('.'))
print(f"Сумма октетов: {answer_sum}")
#16
import sys
sys.setrecursionlimit(20000)
def G(n):
if n <= 20:
return n + 2
if n > 20:
return G(n - 3) + 1
def F(n):
return 3 * G(n - 3) + 7
print(F(37811))
#17
a = [int(x) for x in open('17_17636 (1).txt')]
r = []
mx = max(x for x in a if abs(x) % 10 == 3 and 100 <= abs(x) <= 999)
for i in range(len(a) - 2):
usl1 = (abs(a[i]) % 10 == 3 and 100 <= abs(a[i]) <= 999)
usl2 = (abs(a[i + 1]) % 10 == 3 and 100 <= abs(a[i + 1]) <= 999)
usl3 = (abs(a[i + 2]) % 10 == 3 and 100 <= abs(a[i + 2]) <= 999)
if usl1 or usl2 or usl3:
if a[i] + a[i + 1] + a[i + 2] < mx:
r.append(a[i] + a[i + 1] + a[i + 2])
print(len(r), max(r))
#19-21
def f(s, m):
if s >= 39: return m % 2 == 0
if m == 0: return 0
h = [f(s + 1, m - 1), f(s + 3, m - 1), f(s * 2, m - 1)]
return any(h) if m % 2 != 0 else all(h)
print([s for s in range(1, 39) if f(s, 2)])
print([s for s in range(1, 39) if not f(s, 1) and f(s, 3)])
print([s for s in range(1, 39) if not f(s, 2) and f(s, 4)])
#23
def f(x, y):
if x > y:
return 0
if x == y:
return 1
return f(x + 1, y) + f(x + 2, y) + f(x + 3, y)
print(f(5, 7) * f(7, 11))
#Перевод
def to_base_str(num, base):
alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
res = ""
while num > 0:
digit = num % base
res = alphabet[digit] + res
num //= base
return res if res else "0"
print(to_base_str(255, 16))
print(to_base_str(11, 2))
#простые множители
def f(n):
d=set()
i=2
while i<=n:
while n%i==0:
d.add(i)
n=n//i
i+=1
if len(d)>0:
return d
return 0
print(f(15))