#2
print('x y z w')
for x in range(2):
for y in range(2):
for z in range(2):
for w in range(2):
if (not(y<=x) or (z<=w) or not(z))==False:
print(x, y, z, w)
x y z w
0 0 1 0
1 0 1 0
1 1 1 0
from itertools import product
print('x y z w')
nums=product('01',repeat=4)
for i in nums:
x,y,z,w=i[0],i[1],i[2],i[3]
if (not(y<=x) or (z<=w) or not(z))==False:
print(x, y, z, w)
x y z w
0 0 1 0
1 0 1 0
1 1 1 0
#5
for i in range(1,100):
num=(bin(i)[2:])
if num.count('1')%2==0:
chislo='10'+num[2:]+'0'
if num.count('1')%2!=0:
chislo='11'+num[2:]+'1'
if int(chislo,2)>40:
print (i, int(chislo,2))
break
16 49
#6
from turtle import *
left(90)
for i in range(7):
forward(300)
right(120)
pu()
for x in range(1,9):
for y in range(1,10):
goto(x*30,y*30)
dot(2)
done()
Execution error
ImportError: libtk8.6.so: cannot open shared object file: No such file or directory
#8
count=0
for a in range (1,8):
for b in range (8):
for c in range (8):
for d in range (8):
for e in range (8):
s=str(a)+str(b)+str(c)+str(d)+str(e)
if s.count('6')==1:
if s.index('6')==len(s)-1 and int(s[len(s)-2])%2==0:
count+=1
if s.index('6')==0 and int(s[1])%2==0:
count+=1
if s.index('6')<len(s)-1 and s.index('6')>0 and int(s[s.index('6')-1])%2==0 and int(s[s.index('6')+1])%2==0:
count+=1
print(count)
2961
count=0
from itertools import product
#for a, b, c, d, e in product(range(1,8), range(8), range(8), range(8),range(8)):
nums=product('01234567',repeat=5)
for s in nums:
if s[0]!='0' and s.count('6')==1:
if s[-1]=='6' and int(s[-2])%2==0: count+=1
if s[0]=='6' and int(s[1])%2==0: count+=1
if '6' in s[1:-1] and int(s[s.index('6')-1])%2==0 and int(s[s.index('6')+1])%2==0:
count+=1
print(count)
2961
#8(2)
from itertools import product
k=0
n='16 36 56 76 61 63 65 67'
nn=n.split()
nums=product('01234567',repeat=5)
for n in nums:
numb=''.join(n)
if numb.count('6')==1 and numb[0]!='0':
if all(not(x in numb) for x in nn):
k+=1
print(k)
2961
# загрузка текста из txt
text=t.split(";")
#result = [int(item) for item in text]
result = list(map(int, text))
x=0
y=x+6
counter=double_num=0
while True:
n=0
res6=result[x:y]
for element in res6:
if res6.count(element)>2:
for yy in range(res6.count(element)): res6.remove(element)
# удаление значений больше 2 штук
if res6.count(element)==2:
n+=2
double_num=element
res6.remove(element)
res6.remove(element)
if n==2 and len(res6)==4:
if (sum(res6)/len(res6))<=(double_num*2): counter+=1
print(counter)
if y>=len(result):break
x=x+6
y=x+6
#12
spisok=[]
for num in range(2,1000):
if all(num%delit!=0 for delit in range(2,num)):
spisok.append(num)
for y in range (100):
if y*4+117 in spisok:
print(y)
break
5
#14
for x in range(15):
a15=1*15**4+2*15**3+3*15**2+x*15**1+5
b15=1*15**4+x*15**3+2*15**2+3*15+3
sum10=a15 + b15
if sum10%14==0:
print(x , sum10//14)
break
4 8767
#14(2)
alph='0123456789abcde'
for x in alph:
f=int(f'123{x}5',15)+int(f'1{x}233',15)
if f%14 ==0:
print(x,f//14)
break
4 8767
#15
for a in range(1,100):
if all(((x%2==0) <= (x%3!=0)) or (x+a>=100) for x in range(1,1000)):
print(a)
break
94
#16
#sys.setrecursionlimit(2500)
itog1=itog2=1
for x1 in range(1,2024):
itog1=itog1*x1
for x2 in range(1,2021):
itog2=itog2*x2
print(itog1/itog2)
8266912626.0
!ls /datasets/17
17.txt
#17
with open('17.txt') as f:
nums=[int(x) for x in f]
maxi=[]
s=[]
for i in range(len(nums)):
if nums[i]%10==3:
maxi.append(nums[i])
maximum=0
for i in range(len(nums)-1):
a=abs(nums[i])%10
b=abs(nums[i+1])%10
if ((a==3) and (b!=3)) or ((a!=3) and (b==3)):
if (nums[i]**2+nums[i+1]**2) >= max(maxi)**2:
s.append(nums[i]+nums[i+1])
if nums[i]**2+nums[i+1]**2>maximum:
maximum=nums[i]**2+nums[i+1]**2
print(len(s), maximum)
Execution error
FileNotFoundError: [Errno 2] No such file or directory: '17.txt'
from itertools import product
def f23(x,y,z):
count=0
for i in range(1,z):
nums=product('12',repeat=i)
for numb in nums:
#numb=''.join(n)
a=x
if x==10 and numb.count('2')>1:continue
for ii in numb:
if a==17: break
if ii=='1':a+=1
elif ii=='2' :a*=2
if a==y: count+=1
return count
print(f23(1,10,10)*f23(10,35,25))
98
def f(x,y):
if x>y or x==17:
return 0
elif x==y:
return 1
return f(x+1,y) +f(x*2,y)
print(f(1,10)*f(10,35))
98
!ls /datasets/24
24.txt
#24
with open('24.txt') as f:
let=f.readline()
count,maximum=0,0
#text=''
delta=0
for i in range(len(let)-1):
if (let[i]=='C' or let[i]=='D' or let[i]=='F') and (let[i+1]=='A' or let[i+1]=='O'):
delta=0
#text=text+let[i]+let[i+1]
count+=1
maximum=max(count,maximum)
else: delta+=1
if delta==2:
count=0
#text=''
print(maximum)
Execution error
FileNotFoundError: [Errno 2] No such file or directory: '24.txt'
#24
with open('24.txt') as f:
s=f.readline().replace('C','S').replace('D','S').replace('F','S')
s=s.replace('A','G').replace('O','G')
s=s.replace('SG','*')
k=kmax=0
for i in s:
if i=='*'
k+=1
kmax=max(k,kmax)
else:k=0
print(kmax)
#25
from operator import itemgetter
def f25(chislo):
if int(chislo)%2023==0:
ost=int(chislo)//2023
itog.append(chislo)
itogost.append(ost)
itog=[]
itogost=[]
for i in range(10):
for y in range(1000000):
chislo='1'+str(i)+'21394'
f25(chislo)
chislo='1'+str(i)+'2139'+str(y)+'4'
if int(chislo)>10**10: break
f25(chislo)
itogo=list(zip(itog,itogost))
print(*itogo)
print(sorted(itogo, key=itemgetter(1)))
('1321399324', 653188) ('1421396214', 702618) ('1521393104', 752048) ('162139404', 80148)
[('162139404', 80148), ('1321399324', 653188), ('1421396214', 702618), ('1521393104', 752048)]
for i in range(2023,10**10,2023):
num=str(i)
if num[0]=='1' and num[2:6]=='2139' and num[-1]=='4':
print(i,i//2023)
162139404 80148
1321399324 653188
1421396214 702618
1521393104 752048
!ls /datasets/text26
26.txt
#26
with open('26.txt') as f:
s=[int(x) for x in f]
s=sorted(s[1:],reverse=True)
k,mini=1,s[0]
for i in range(1,len(s)):
if s[i]+3<=mini:
mini=s[i]
k+=1
print(k,mini)
Execution error
FileNotFoundError: [Errno 2] No such file or directory: '26.txt'
with open('27_A.txt') as f:
n=f.readlines()
data=[]
for x in f:
number,prob=map(int,x.split())
if prob%36==0:
data.append([number,prob//36])
else:
data.append([number,prob//36+1])
min_s=10**30
for i in range(n):
s=0
for j in range(n):
s+=abs(data[i][0]-data[j][0]*data[j][1])
min_s=min(s,min_s)
print(min_s)
cost_punkt=[]
data=[]
konteiners=0
with open('27_A.txt') as f:
d=f.readlines()
punkts=d[0]
for i in range (1,len(d)):
data.append(d[i].split())
for i in range (0,len(data)):
position0=int(data[i][0])
cost=0
for y in range (0,len(data)):
kont=round(int(data[y][1])/36)
if round(int(data[y][1])/36) < int(data[y][1])/36:
kont=(int(data[y][1])//36) + 1
cost+=abs(int(data[y][0])-position0) * kont
#print(f'cost={cost} kont={konteiners}-{int(data[y][1])/36} разница пути пункта={abs(int(data[y][0])-position0)}')
cost_punkt.append(cost)
print(i, cost)
print(f"{min(cost_punkt)} номер пункта-{cost_punkt.index(min(cost_punkt))} всего пунктов {punkts}")
0 109241
1 107827
2 107239
3 106663
4 104763
5 100531
6 95435
7 91655
8 90959
9 86927
10 85793
11 81153
12 80679
13 80527
14 80089
15 79947
16 76587
17 76043
18 69745
19 69489
20 68993
21 67673
22 65585
23 65145
24 64533
25 64239
26 62583
27 61323
28 61239
29 60927
30 59787
31 57815
32 57221
33 57161
34 56639
35 55937
36 55001
37 54701
38 53827
39 52861
40 52747
41 52639
42 52435
43 52045
44 51681
45 51637
46 51403
47 51193
48 51133
49 51079
50 51063
51 51063
52 51091
53 51099
54 51179
55 51361
56 51741
57 51807
58 51999
59 52083
60 52525
61 52677
62 52877
63 53229
64 53643
65 54123
66 54323
67 54971
68 55091
69 55421
70 55853
71 56613
72 57093
73 58211
74 59201
75 60329
76 61329
77 61641
78 64171
79 64513
80 65233
81 66997
82 67253
83 67789
84 67927
85 69915
86 70937
87 73037
88 76837
89 77617
90 77775
91 78759
92 78929
93 81539
94 83159
95 85577
96 87305
97 92931
98 94695
99 97927
51063 номер пункта-50 всего пунктов 100
#27B часть загрузки данных
cost_punkt=[]
data=[]
konteiners=0
with open('27_B.txt') as f:
d=f.readlines()
punkts=d[0]
for i in range (1,len(d)):
data.append(d[i].split())
print(punkts)
1100000
#вторая часть программы методом половинного деления в ручном управлении
def cost(metka):
position0=int(data[metka][0])
cost=0
for y in range (0,len(data)):
konteiners=round(int(data[y][1])/36)
if round(int(data[y][1])/36) < int(data[y][1])/36:
konteiners=(int(data[y][1])//36) + 1
cost+=abs(int(data[y][0])-position0) * konteiners
return cost
mini=1000000000
num_pu=0
count_i=0
print(punkts)
metka=int(punkts)//2
first=first_etalon=cost(metka)
second=second_etalon=cost(metka+1)
metka_up=0
metka_down=len(data)-1
while True:
first_etalon=first
second_etalon=second
first=cost(metka)
second=cost(metka+1)
print(f"{first} \n{second}")
if first>second:
first_etalon=first
second_etalon=second
print(metka,">")
metka_up=metka
delta=(metka_down-metka_up)//2
metka=metka + delta
print(metka)
if first<second:
metka_down=metka
print(metka,"<")
delta=(metka_down-metka_up)//2
metka=metka - delta
print(metka)
1100000
5634690655428
5634690658875
550000 <
275000
7043778479723
7043776224901
275000 >
412500
5986229331739
5986224262300
412500 >
481250
5722204708283
5722204427476
481250 >
515625
5656265059385
5656263242804
515625 >
532812
5639974331526
5639973637376
532812 >
541406
5635991184419
5635990877402
541406 >
545703
5634985029164
5634984864694
545703 >
547851
5634753622945
5634753592277
547851 >
548925
5634700785009
5634700755732
548925 >
549462
5634690533528
5634690507253
549462 >
549731
5634689220152
5634689220268
549731 <
549597
5634689602659
5634689601096
549597 >
549664
5634689303068
5634689302072
549664 >
549697
5634689237161
5634689234056
549697 >
549714
5634689221784
5634689220794
549714 >
549722
5634689219663
5634689219399
549722 >
549726
5634689219362
5634689219488
549726 <
549724
5634689219329
5634689219332
549724 <
549723
5634689219399
5634689219329
549723 >
549723
5634689219399
5634689219329
549723 >
549723
5634689219399
5634689219329
549723 >
549723
5634689219399
5634689219329
549723 >
549723
Execution error
KeyboardInterrupt: