[TP3_bonus] Question 4

J'ai un problème avec ma fonction temps d'arrêt on dirait....
This commit is contained in:
Suwako Moriya 2019-11-28 10:15:56 +01:00
parent 8880f7c0b9
commit 236bb61ec3
Signed by: SuwakoMmh
GPG Key ID: A27482B806F13CD5
5 changed files with 150 additions and 3 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 KiB

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

@ -148,6 +148,6 @@ def bigpicture(n=2, size=128):
new_im.paste(images.pop(0), (int(window[1][0]), int(window[0][0])))
new_im.save('Bigpicture.png')
bigpicture(n=3, size=512)
bigpicture(n=3, size=1024)
#mandeld(n=512, lim=255, color=(1,1,1), threads=10, window=[(-2,2),(-2,2)])
#[((-2.0, 0.0), (-2.0, 0.0)), ((-2.0, 0.0), (0.0, 2.0)), ((0.0, 2.0), (-2.0, 0.0)), ((0.0, 2.0), (0.0, 2.0))]

113
TP3/TP 3 etudiants.py Executable file
View File

@ -0,0 +1,113 @@
######Exercice 1 ######
from math import*
##Question 1:##
def multiplesde7(n):
l=[]
for i in range(n):
if i%7==0:
l+=[i]
return l
print(multiplesde7(100))
##Question 2##
Un nombre (n) est premier si aucun nombre inferieur a sqrt(n) en divise (n).
On vérifie ici ce théoreme en testant sucessivement la divisibilité des (i) par (n) avec (i) variant de 2 a sqrt(n)
##Question 3##
def isprime(n):
s=int(sqrt(n))
t=True
i=2
while i<=s and t==True:
if n% i==0:
t=False
i+=1
return(t)
def listepremier(n):
l=[]
for i in range(2,n+1):
if isprime(i):
l+=[i]
return l
##Question 4##
def premier():
p=[]
n=2
while len(p)!=100:
if isprime(n):
p+=[n]
n+=1
return p
##Question 5##
def jumeaux():
l=[]
for i in range(2,3000):
if isprime(i) and isprime(i+2):
l+=[(i,i+2)]
return l
##Question 6#
n=0
while 1<2:
a=2**(2**n) +1
if isprime(a) == False:
print(False, n)
break
n+=1
## Question 7 BONUS (à traiter plus tard) ##
######Exercice 2######
##Question 1##
a=1
print(a)
for i in range(100):
b=(1/2)*(a+(2/a))
print(b)
a=b
##Question 2##
a=1
print(a)
for i in range(10):
b=(1/2)*(a+(2/a))
print((b)**2 - 2)
a=b
# les valeurs tendent très rapidement vers 0 car sqrt(2)**2 - 2 = 0
##Question 3#
a=1
l=[1]
for i in range(10):
b=(1/2)*(a+(2/a))
l+=[b**2-2]
a=b
i=0
while 1<2:
if l[i]<0.00002
print(i)
break
i+=1
# On cherche a encadrer |Un**2 -2|
#Sachant que la condition d'arrêt de départ est :
#|Un-sqrt(2)|<10**-5
#Or x->sqrt(x) est 1/2 lispsiptienne => |f(y)-f(x)|<1/2 |x-y| On pose x=Un**2 et y=2=(sqrt(2))**2
#Ainsi, on a |Un -sqrt(2)|<1/2|Un**2-2|
#Or on souhaite avoir |Un -sqrt(2)|<10**-5. Une proposition plus forte consiste à dire:
# |Un-sqrt(2)|<1/2|Un**2-2|<10**-5
#<=> 2*|Un-sqrt(2)|<|Un**2-2|<2*10**-5
#D'ou la condition d'arrêt : |Un**2-2|<2*10**-5

View File

@ -168,4 +168,5 @@ def hauteur(n):
if c>4999 and c%5000==0 and not input("continuer ? (oui/non) >").lower().startswith('o'):
break
print(N)
return c
return c

View File

@ -47,6 +47,39 @@ import time
def verification(m):# m=1000000 -> 60 sec
start = time.time()
for c in range(2, m+1):
for c in range(0, m+1, ):
tempsdarret(c)
return time.time() - start
# c)
# Question 4
# a)
def altitudemax(borne):
res = {"c":0, "altitude":0}
for c in range(3, borne+1, 4):
current = altitude(c)
if current > res["altitude"]:
res.update({"c":c, "altitude":current})
return res
def tempsdarretmax(borne): # {'c': 665215, 'temps': 354}
res = {"c": 0, "temps": 0}
for c in range(3, borne+1, 4):
current = tempsdarret(c)
if current > res["temps"]:
res.update({"c": c, "temps": current})
return res
def tempsdarretrecord(borne):
res = {"c": 0, "temps": 0}
L=[]
for c in range(2, borne+1):
current = tempsdarret(c)
if current > res["temps"]:
res.update({"c": c, "temps": current})
L.append({"c": c, "temps": current})
return L