added few pieces of code

This commit is contained in:
2019-05-11 16:17:22 +02:00
parent 51b1bd06e9
commit 7f1cbe08e3
9 changed files with 314 additions and 1 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ def searchCaptcha(filename):
X=x-234
Y=y+34
return [X,Y]
return None
raise Exception("No captcha was found in this picture.")
def resolveCaptcha(url):
+36
View File
@@ -0,0 +1,36 @@
from __future__ import unicode_literals
import sys
#import youtube_dl
print(sys.version)
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print('Done downloading, now converting ...')
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://youtu.be/i8q8fFs3kTM?list=PLlqZM4covn1GeiFmvbi8YppviPVUH2Q_9"])
+133
View File
@@ -0,0 +1,133 @@
#Hugues de Rubin de Cervens
#Marc Partensky
#Louise De Servigny
from scipy.optimize import bisect,newton
import math
f=lambda x:x**2-2
#1)a) On définit f : x-->x^2-2. f s'annule en sqrt(2) et -sqrt(2). Or leurs valeurs décimales ne sont pas fini.
"""b)DONNEES (a,b,e)
x<-(a+b)/2
TANT QUE abs(x^2-2)>e FAIRE:
SI f(a)*f(b)>0: FAIRE:
a<-x
SINON FAIRE:
b<-x
x<-(a+b)/2
FIN TANT QUE
AFFICHER x
"""
#c)
def ZeroD(f,a,b,e):
x=(a+b)/2
while abs(f(x))>e:
if f(a)*f(x)>0:
a=x
else:
b=x
x=(a+b)/2
return x
#d)
print("ZeroD:",ZeroD(f,1,2,e=10**(-12)))
print(math.sqrt(2))
#2)a))
print(bisect(f,1,2))
#b)
print("ZeroD:",ZeroD(f,1,2,e=10**(-12)))
#II) a)
#b)Données(f,a,b,n)
"""
t : x-->(-f(a)*(b-a))/(f(b)-f(a))+a
c=t(a,b)
Pour i parcourant n
c=t(a,b)
Si f(a)f(c)>0
a=c
Sinon
b=c
Afficher c
"""
#c)
def ZeroL(f,a,b,n):
t=lambda a,b:-f(a)*(b-a)/(f(b)-f(a))+a
c=t(a,b)
for i in range(n):
c=t(a,b)
if f(a)*f(c)>0:
a=c
else:
b=c
return c
#d)
print("ZeroL:",ZeroL(f,1,2,10))
print(math.sqrt(2))
#e)
def ZeroDC(f,a,b,e):
x=(a+b)/2
t=0
while abs(f(x))>e:
t+=1
if f(a)*f(x)>0:
a=x
else:
b=x
x=(a+b)/2
return (x,t)
#f)
print("ZeroDC:",ZeroDC(f,1,2,10**(-12)))
#4)
print(newton(f,1,maxiter=20))
#III)
#a) Figure...
#b) Algorithme
"""Données(f,a,b,n)
fp : a-->(f(a+h)-f(a))/h
e=10^-10
c=b
Pour i parcourant n
c=c-f(c)/fp(c,e)
Si f(a)f(c)>0
a=c
SINON
b=c
Afficher c
"""
#c)
def ZeroN(f,a,b,n):
fp=lambda a,h:(f(a+h)-f(a))/h
e=10**(-10)
c=b
for i in range(n):
c=c-f(c)/fp(c,e)
if f(a)*f(c)>0:
a=c
else:
b=c
return c
#d)
print("ZeroN:",ZeroN(f,1,2,20))
print(math.sqrt(2))
#6)
#a)
print(newton(f,1,maxiter=20))
#b)
print("ZeroN:",ZeroN(f,1,2,20))
+102
View File
@@ -0,0 +1,102 @@
from polynomial import Polynomial
def getInteger(message):
number=0
for i,character in enumerate(message):
c=int(character)
number+=c*2**i
return number
class TByte(int):
def __init__(self,other):
"""Create somekind of a byte value using integers at its core."""
super().__init__()
self.correct()
def correct(self):
"""Correct the byte."""
self%=369
def __add__(self,other):
"""Add two bytes."""
result=other+self
result.correct()
return result
__sub__=__add__
def __str__(self):
"""Return the string representation of the byte."""
conversion=lambda n:[(n//(2**i))%2 for i in range(7,-1,-1)]
return str(conversion(self))
def __call__(self):
pass
class ReedSolomon:
def N(message):
"""Return the number 'n' of characters of the message."""
return len(message)
def StrToAscii(message):
"""Return the ascii code for each letter of the message."""
ascii_code=[]
for character in message:
ascii_character=ord(character)
ascii_code.append(ascii_character)
return ascii_code
def AsciiToList(ascii_code):
"""Return the list code for the ascii characters by converting in binary
each ascii character and concatenating the results."""
conversion=lambda n:[(n//(2**i))%2 for i in range(7,-1,-1)]
list_code=[]
for ascii_character in ascii_code:
list_character=conversion(ascii_character)
list_code+=list_character
return list_code
def __init__(self,alpha=1,k=256):
"""Create a Reed Solomon encoder and decoder"""
sefl.alpha=alpha
self.k=k
def StrToByte(self,message,k):
"""Convert a str message in byte."""
if k==256:
return ReedSolomon.StrToAscii(message)
def StrToList(self,message,k=256):
"""Convert the message in list code."""
byte_code=self.StrToByte(message,k)
list_code=self.ByteToList(ascii_code)
return list_code
def encode(self,message):
"""Encode the message."""
self.n=ReedSolomon.N(message)
list_code=self.StrToList(message,k)
A=Polynomial(list_code)
if __name__=="__main__":
message="salut comment ca va"
#coder=ReedSolomon()
#code=coder.encode(message)
#message=coder.decode(code)
message="100011101"
n=getInteger(message)
print(n)
b=TByte(256)
print(b)
print(512%369)
conversion=lambda n:[(n//(2**i))%2 for i in range(7,-1,-1)]
print(conversion(143))
Binary file not shown.
Binary file not shown.
+41
View File
@@ -0,0 +1,41 @@
#a=["a","b","c","d","e"]
#a=list(range(3))
a=[a for a in "abcdefgh"]
#print(len(a))
def permutations(l):
if len(l)==2:
return [(l[0],l[1]),(l[1],l[0])]
else:
result=[]
for i in range(len(l)):
b=l[:]
del b[i]
result+=[tuple(l[i])+a for a in permutations(b)]
return result
def prod(l):
"""Return the product of the list l."""
r=1
for a in l:
r*=a
return r
def facto(n):
"""Return the factorial of the number n."""
return prod(range(1,n+1))
print(facto(10))
def getPermutation(l,n):
"""Return the permutation number n."""
for n i
#print(["".join(b) for b in permutations(a)])
+1
View File
@@ -0,0 +1 @@
print([(x,x**2) for x in range(32)])