Change of locations

This commit is contained in:
2019-09-02 17:56:04 +02:00
parent f7050f845c
commit 832fab9a64
18 changed files with 724 additions and 11 deletions
Vendored
BIN
View File
Binary file not shown.
+28
View File
@@ -0,0 +1,28 @@
# import the necessary packages
import numpy as np
import argparse
import cv2
import cv2.cv as cv
circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT)
img = cv2.imread("numeriser.png")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray,cv2.HOUGH_GRADIENT)
# ensure at least some circles were found
if circles is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circles = np.round(circles[0, :]).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circles:
# draw the circle in the output image, then draw a rectangle
# corresponding to the center of the circle
cv2.circle(output, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
# show the output image
cv2.imshow("output", np.hstack([image, output]))
cv2.waitKey(0)
+81
View File
@@ -0,0 +1,81 @@
l="""1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1"""
nbLivres, nbJours = map(int, input().strip().split())
bibliotheque=list(range(nbLivres))
clients=[]
def visiter(bibliotheque,clients):
bibliotheque=retirer(bibliotheque,clients)
bibliotheque=ajouter(bibliotheque,clients)
return bibliotheque
def ajouter(bibliotheque,clients):
aujourdhui=len(clients)
for (jour,clients_aujourdhui) in enumerate(clients):
for client in clients_aujourdhui:
indice, duree = client
if jour+duree == aujourdhui:
bibliotheque.append(indice)
return bibliotheque
def retirer(bibliotheque, clients):
if len(clients)==0:
return bibliotheque
for client in clients[-1]:
indice = client[0]
if indice in bibliotheque:
bibliotheque.remove(indice)
print(1)
else:
print(0)
return bibliotheque
for _ in range(1, nbJours + 1):
nbClients = int(input().strip())
nouveaux_clients=[]
for _ in range(0, nbClients):
indice, duree = map(int, input().strip().split())
nouveaux_clients.append([indice, duree])
clients.append(nouveaux_clients)
bibliotheque=visiter(bibliotheque,clients)
print(bibliotheque)
+3
View File
@@ -0,0 +1,3 @@
from Solver import *
print(solve("2x+5=6"))
+91
View File
@@ -0,0 +1,91 @@
from set import *
from equation import *
from expression import *
def __init__(self):
self.solved=False
self.valid_equation=None
self.valid_typeCheck=None
self.comparisons=None
self.unknowns=None
self.resolution=[]
self.loadVocabulary()
def __call__(self,input):
self.input=input
self.type=type(self.input)
self.output=""
self.analyse()
self.end()
return self.output
def loadVocabulary(self):
self.lower_case_alphabet="abcdefghijklmnopqrstuvwxyz"
self.upper_case_alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
self.all_case_alphabet=self.lower_case_alphabet+self.upper_case_alphabet
self.operations="+-*/!%^()"
self.comparisons="=<>~"
self.numbers="0123456789"
self.valid_types=[str]
def analyse(self):
self.isValidType(self.input)
if not self.valid_typeCheck:
self.output="The type is not valid.\n"
else:
self.isEquation(self.input)
if self.valid_equation:
self.equation=self.input
self.solveEquation(self.equation)
else:
self.output="The input isn't an equation."
def isValidType(self,input):
if self.type in self.valid_types:
self.valid_typeCheck=True
else:
self.output+="Insert an input of type:\n"
self.output+=str(self.valid_types)+"\n"
self.valid_typeCheck=False
def isEquation(self,input):
valid_equation=True
comparisons=intersection(input,self.comparisons)
unknowns=intersection(input,self.all_case_alphabet)
operations=intersection(input,self.operations)
if len(comparisons)==0:
valid_equation=False
if len(unknowns)==0:
valid_equation=False
self.valid_equation=valid_equation
def solveEquation(self,equation):
self.equation=equation
self.step=0
self.max_steps=100
while self.step<self.max_steps and not self.solved:
self.resolution.append(self.equation)
self.unknowns=intersection(equation,self.all_case_alphabet)
self.comparisons=intersection(equation,self.comparisons)
self.operations=intersection(equation,self.operations)
self.equation=isolate(equation)
if len(self.unknowns)==1 and self.comparisons==["="] and self.operations:
pass
self.output+="Resolution: \n"
self.output+=str(self.resolution)+"\n"
def end(self):
if not self.solved:
if len(self.output)==0:
self.output+="The resolution of this problem still needs to be implemented."
else:
self.output+="The resolution of this problem is being implemented."
solve=Solver()
if __name__=="__main__":
solve(input("Enter: "))
+11
View File
@@ -0,0 +1,11 @@
def countCharacters(expression,character):
r=0
for i in input:
if i==character:
r+=1
return count
def simplifyParenthesis(expression):
return expression
+57
View File
@@ -0,0 +1,57 @@
import socket
import select
import errno
import sys
HEADER_LENGTH=10
IP="172.16.0.27."
#IP="86.242.99.166"
IP='192.168.1.11'
IP='localhost'
IP=socket.gethostname()
IP='localhost'
print(IP)
PORT=1236
my_username=input("username: ")
client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client_socket.connect((IP,PORT))
client_socket.setblocking(False)
username=my_username.encode('utf-8')
username_header=f"{len(username):<{HEADER_LENGTH}}".encode('utf-8')
client_socket.send(username_header+username)
while True:
message=input(f"{my_username}>")
if message:
message=message.encode('utf-8')
message_header=f"{len(message):<{HEADER_LENGTH}}".encode('utf-8')
client_socket.send(message_header+message)
try:
while True:
#receive things
username_header=client_socket.recv(HEADER_LENGTH)
if not len(username_header):
print("connection closed by the server")
sys.exit()
username_length=int(username_header.decode('utf-8').strip())
username=client_scoket.recv(username_length).decode('utf-8')
message_header=client_socket.recv(HEADER_LENGTH)
message_length=int(message_header.decode('utf-8').strip())
message=client.socket.recv(message_length).decode('utf-8')
print(f"{username}>{message}")
except IOError as e:
if e.errno != errno.EAGAIN and e.errno != errno.EWOULDBLOCK:
print("reading error",str(e))
sys.exit()
continue
except Exception as e:
print("general error",str(e))
sys.exit()
+70
View File
@@ -0,0 +1,70 @@
import socket
import select
HEADER_LENGTH=10
IP="172.16.0.27."
#IP="86.242.99.166"
#IP='192.168.1.11'
IP=socket.gethostname()
IP=''
print(IP)
PORT=1236
server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server_socket.bind((IP,PORT))
server_socket.listen()
sockets_list=[server_socket]
clients={}
def receive_message(client_socket):
try:
message_header=client_socket.recv(HEADER_LENGTH)
if not len(message_header):
return False
else:
message_length=int(message_header.decode("utf-8").strip())
return {"header":message_header,"data":client_socket.recv(message_length)}
except:
return False
while True:
read_sockets,_,exception_sockets=select.select(sockets_list,[],sockets_list)
for notified_socket in read_sockets:
if notified_socket==server_socket:
client_socket,client_address=server_socket
user = receive_message(client_socket)
if user is False:
continue
sockets_list.append(client_socket)
clients[client_socket]=user
print(f"Accepted new connection from {client_address[0]}:{client_address[1]} username: {user['data'].decode('utf-8')}")
else:
message=receive_message(notified_socket)
if message is False:
m=clients[notified_socket]['data'].decode('utf-8')
print("Closed connection from {}".format(m))
sockets_list.remove(notified_socket)
del clients[notified_sockets]
continue
user = clients[notified_socket]
print(f"Received message from {user['data'].decode('utf-8')}: {message['data'].decode('utf-8')}")
for client_socket in clients:
if client_socket != notified_socket:
client_socket.send(user['header']+user['data']+message['header']+message['data'])
for notified_socket in exception_sockets:
sockets_list.remove(notified_socket)
del clients[notified_socket]
+58
View File
@@ -0,0 +1,58 @@
import socket
import select
import errno
import sys
import time
HEADER_LENGTH=10
IP="127.0.0.1"
IP=socket.gethostname()
PORT=1238
to=time.time()
duration=20
my_username="Marc"
client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client_socket.connect((IP,PORT))
client_socket.setblocking(False)
username=my_username.encode('utf-8')
username_header=f"{len(username):<{HEADER_LENGTH}}".encode('utf-8')
client_socket.send(username_header+username)
while time.time()-to<duration:
message="hi im "+my_username
if message:
message=message.encode('utf-8')
message_header=f"{len(message):<{HEADER_LENGTH}}".encode('utf-8')
client_socket.send(message_header+message)
try:
while True:
#receive things
username_header=client_socket.recv(HEADER_LENGTH)
if not len(username_header):
print("Client: Connection closed by the server")
sys.exit()
username_length=int(username_header.decode('utf-8').strip())
username=client_socket.recv(username_length).decode('utf-8')
message_header=client_socket.recv(HEADER_LENGTH)
message_length=int(message_header.decode('utf-8').strip())
message=client_socket.recv(message_length).decode('utf-8')
print(f"Client: {username}>{message}")
except IOError as e:
if e.errno != errno.EAGAIN or e.errno != errno.EWOULDBLOCK:
print("Client: Reading error",str(e))
sys.exit()
continue
except Exception as e:
print("Client: General error",str(e))
sys.exit()
print("the client is done running")
+17 -9
View File
@@ -1,13 +1,18 @@
import socket
import select
import time
HEADER_LENGTH=10
IP="127.0.0.1"
PORT=1234
IP=socket.gethostname()
PORT=1238
to=time.time()
duration=20
server_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server_socket.bind((IP,PORT))
@@ -28,11 +33,11 @@ def receive_message(client_socket):
except:
return False
while True:
read_sockets,_,exception_sockets=select.select(sockets_list,[],sockets_lists)
while time.time()-to<duration:
read_sockets,_,exception_sockets=select.select(sockets_list,[],sockets_list)
for notified_socket in read_sockets:
if notified_socket==server_socket:
client_socket,client_address=server_socket
client_socket,client_address=server_socket.accept()
user = receive_message(client_socket)
if user is False:
@@ -42,19 +47,19 @@ while True:
clients[client_socket]=user
print(f"Accepted new connection from {client_address[0]}:{client_address[1]} username: {user['data'].decode('utf-8')}")
print(f"Server: Accepted new connection from {client_address[0]}:{client_address[1]} username: {user['data'].decode('utf-8')}")
else:
message=receive_message(notified_socket)
if message is False:
print(f"Closed connection from {clients[notified_socket]['data'].decode('utf-8')})
print("Server: Closed connection from {}".format(clients[notified_socket]['data'].decode('utf-8')))
sockets_list.remove(notified_socket)
del clients[notified_sockets]
del clients[notified_socket]
continue
user = clients[notified_socket]
print(f"Received message from {user['data'].decode('utf-8')}: {message['data'].decode('utf-8')}")
print(f"Server: Received message from {user['data'].decode('utf-8')}: {message['data'].decode('utf-8')}")
for client_socket in clients:
if client_socket != notified_socket:
client_socket.send(user['header']+user['data']+message['header']+message['data'])
@@ -62,3 +67,6 @@ while True:
for notified_socket in exception_sockets:
sockets_list.remove(notified_socket)
del clients[notified_socket]
print("the server is done running")
+96
View File
@@ -0,0 +1,96 @@
import copy
"""
objectif = int(input("saisir le nb a obtenir: "))
n = int(input("saisir la quantité de nombres disponibles: "))
nb = []
for i in range(n):
nb.append(int(input().strip()))
"""
objectif = 8136
numbers = [4,5,6,7,8,9]
def couples(A):
ans = []
n = len(A)
for i in range(n - 1):
for j in range(i + 1, n):
ans.append([A[i], A[j]])
return ans
toInt=lambda x:list(map(eval,x))
toStr=lambda x:list(map(str,x))
def operations(A):
a, b = A
ans = []
ans=[]
ans.append(a+"+"+b)
ans.append(a+"-"+b)
ans.append(b+"-"+a)
if eval(b) != 0:
ans.append(a+"/"+b)
elif eval(a) != 0:
ans.append(b+"/"+a)
ans.append(a+"*"+b)
ans=["("+a+")" for a in ans]
return ans
def adapt(A, result, couple):
B = A[:]
a, b = couple
B.remove(a)
B.remove(b)
B.append(result)
return B
#"(5*2)+4*5-2"
#[1,5,6,2,9]
#["1","5","6","2","9"]
#[6,6,2,9]
#["1+5","6","2","9"]
#["1+5","6","11"]
#[6,6,11]
#[36,2,9]
#["(1+5)*6","2","9"]
[2,2,1]
def resoudre(nb, objectif):
for couple in couples(nb):
for result in operations(couple):
nb_ = adapt(nb, result, couple)
if eval(result) == objectif:
print(result)
return True
if resoudre(nb_, objectif):
return True
return False
def resoudreTout(nb, objectif,historique=[]):
for couple in couples(nb):
for result in operations(couple):
nb_ = adapt(nb, result, couple)
if eval(result) == objectif:
historique.append(objectif)
return True
if resoudreTout(nb_, objectif):
return True
return False
if __name__ == "__main__":
numbers=toStr(numbers)
resultat=resoudre(numbers, objectif)
print(resultat)
+2 -2
View File
@@ -227,13 +227,13 @@ class Polynomial:
extrema=[neglim]+old_extrema+[poslim]
for i in range(len(extrema)-1):
if derivative(extrema[i])*derivative(extrema[i+1])<=0:
new_extrema.append(derivative.gradientDescent(extrema[i],extrema[i+1]))
new_extrema.append(derivative.TVI(extrema[i],extrema[i+1]))
old_extrema=new_extrema[:]
return new_extrema
def gradientDescent(self,xa,xb,precision=10e-10):
def TVI(self,xa,xb,precision=10e-10):
"""Return a float value x between a and b for which the polynomial canceled itself."""
"""Does that based on theoreme of intermediate value with dichotomy."""
if self(xa)*self(xb)>0:
+69
View File
@@ -0,0 +1,69 @@
import random
import copy
#import numpy as np
#import pygame
#from pygame.locals import *
ultimate_grid = [[8,1,2,7,5,3,6,4,9],
[9,4,3,6,8,2,1,7,5],
[6,7,5,4,9,1,2,8,3],
[1,5,4,2,3,7,8,9,6],
[3,6,9,8,4,5,7,2,1],
[2,8,7,1,6,9,7,3,4],
[5,2,1,9,7,4,3,6,8],
[4,3,8,5,2,6,9,1,7],
[7,9,6,3,1,8,4,5,2]]
message="812753649 943682175 675491283 154237896 369845721 287169734 521974368 438526917 796318452"
class Sudoku:
def createFromString(chaine):
"""Create a grid from string."""
chaines=chaine.split()
grid=[list(map(int,chaines[i])) for i in range(len(chaines))]
return Sudoku(grid)
def __init__(self,grid):
"""Create a sudoku grid."""
self.grid=grid
def initPygame(self):
pass
def exchangeLinesSquares(self,i,j):
index1 = 3 * i
for k in range(index1,index1+3):
#self.grid[x1][y1],self.grid[x2][y2]=self.grid[x2][y2],self.grid[x1][y1]
self.exchangeLinesCase(k, j*3+k)
def exchangeLinesCase(self, i, j):
self.grid[i],self.grid[j]=self.grid[j],self.grid[i]
def exchangeColumnsSquares(self,j,i):
index1 = 3 * i
for k in range(index1,index1+3):
#self.grid[x1][y1],self.grid[x2][y2]=self.grid[x2][y2],self.grid[x1][y1]
self.exchangeLinesCase(k, j*3+k)
def exchangeColumnsCase(self, i, j):
c=copy.deepcopy(self.grid[:][j])
print(s,end='\n'*2)
self.grid[:][j]=copy.deepcopy(self.grid[:][i])
print(s)
self.grid[:][i]=c
def show(self):
"""Show the sudoku on the screen."""
pass
def __str__(self):
return "\n".join(map(str,[" ".join(map(str,c)) for c in self.grid]))
if __name__=="__main__":
s=Sudoku.createFromString(message)
#seed=random.randint()
# sudoku=Sudoku(seed)
print(s,end='\n'*2)
s.exchangeColumnsCase(0,2)
print(s)
+133
View File
@@ -0,0 +1,133 @@
import math
from functools import reduce
from itertools import cycle
n=1.0088284e+90
print(n)
n=n*math.factorial(54)
print(n)
c=math.log(n,26)
print(c)
def partitions(n):
parts = [1]+[0]*n
for t in range(1, n+1):
for i, x in enumerate(range(t, n+1)):
parts[x] += parts[i]
return parts[n]
def prod(l):
return reduce(lambda x1,x2:x1*x2,l)
print(prod([1,3]))
print(partitions(1000))
def adapt(l,b):
return [0]*(len(b)-len(l))+l
def decompose(n):
return list(map(int,str(n)))
def compose(l):
return int("".join(map(str,l)))
print(decompose(1432))
def addInBase(l1,l2,b):
l=[]
s=0
for i in range(-1,-len(b)-1,-1):
r=(l1[i]+l2[i]+s)%b[i]
s=(l1[i]+l2[i]+s)//b[i]
l.append(r)
return list(reversed(l))
def getInBase10(l,b):
return l[-1]+sum([l[i]*prod(b[i+1:]) for i in range(-2,-len(l)-1,-1)])
def getInBase10(l,b):
l=adapt(l,b)
s=l[0]
l.reverse()
b.reverse()
p=1
for i in range(1,len(b)-1):
p*=b[i]
s+=l[i]*p
return s
def getFromBase10(n,b):
b.reverse()
l=[]
for i in range(len(b)):
r=n%b[i]
n=n//b[i]
l.append(r)
l.reverse()
return l
def convert(l,b1,b2):
l.reverse()
b1.reverse()
b2.reverse()
nl=[]
i=0
n1=0
n2=0
while l.count(0)!=len(l):
if b1[n1]>b2[n2]:
r=l[i]%b2[n2]
s=l[i]//b2[n2]
nl.append(r)
i+=1
def convertEasy(l,b1,b2):
n=getInBase10(l,b1)
l=getFromBase10(n,b2)
return l
#[1,0,0,0] [10,10,10,10]
#[0,16,40] [24,60,60]
c=10
hms=[24,60,60]
binary=[2]*c
decimal=[2]*c
t1=[12,12,30]
t2=[5,0,30]
r=addInBase(t1,t2,hms)
print(r)
print(compose([10,5,5]))
print(getInBase10([2,16,40],hms))
print(getFromBase10(1000,hms))
t1d=convertEasy(t1,hms,decimal)
print(t1d)
t1b=convertEasy(t1d,decimal,binary)
print(t1b)
t1=convertEasy(t1b,binary,hms)
print(t1)
print(convertEasy([1,0,0],decimal,hms))
print(getInBase10([1,0],decimal))
print(adapt([1,0],decimal))
+8
View File
@@ -0,0 +1,8 @@
import itertools
#print(list(itertools.combinations(list(range(2)),2)))
#print([(i,j) for i in range(2) for j in range(2)])
print(list(itertools.product(list(range(2)),repeat=2)))