diff --git a/.DS_Store b/.DS_Store index ecfd01c..f76199e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Detection/detect_circles.py b/Detection/detect_circles.py new file mode 100644 index 0000000..aa5be13 --- /dev/null +++ b/Detection/detect_circles.py @@ -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) diff --git a/France io/france io.py b/France io/france io.py new file mode 100644 index 0000000..b079456 --- /dev/null +++ b/France io/france io.py @@ -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) diff --git a/Maths Stuff/Main.py b/Maths Stuff/Main.py new file mode 100644 index 0000000..288c937 --- /dev/null +++ b/Maths Stuff/Main.py @@ -0,0 +1,3 @@ +from Solver import * + +print(solve("2x+5=6")) diff --git a/Maths Stuff/Solver.py b/Maths Stuff/Solver.py new file mode 100644 index 0000000..63d4b8e --- /dev/null +++ b/Maths Stuff/Solver.py @@ -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") + + 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() diff --git a/Socket/chat server.py b/Socket/chat server.py new file mode 100644 index 0000000..a68f529 --- /dev/null +++ b/Socket/chat server.py @@ -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] diff --git a/Sockets/client.py b/Socket/client.py similarity index 100% rename from Sockets/client.py rename to Socket/client.py diff --git a/Sockets/server.py b/Socket/server.py similarity index 100% rename from Sockets/server.py rename to Socket/server.py diff --git a/Sockets/test infinite loop.py b/Socket/test infinite loop.py similarity index 100% rename from Sockets/test infinite loop.py rename to Socket/test infinite loop.py diff --git a/Sockets/chat client.py b/Sockets/chat client.py index e69de29..c67a0a4 100644 --- a/Sockets/chat client.py +++ b/Sockets/chat client.py @@ -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{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") diff --git a/Sockets/chat server.py b/Sockets/chat server.py index 69dc62d..b325a21 100644 --- a/Sockets/chat server.py +++ b/Sockets/chat server.py @@ -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()-to0: diff --git a/Teletype/sudoku.py b/Teletype/sudoku.py new file mode 100644 index 0000000..f25ab6d --- /dev/null +++ b/Teletype/sudoku.py @@ -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) diff --git a/Tests/maths calculation.py b/Tests/maths calculation.py new file mode 100644 index 0000000..6103774 --- /dev/null +++ b/Tests/maths calculation.py @@ -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)) diff --git a/Tests/test3.py b/Tests/test3.py new file mode 100644 index 0000000..e7e1f3f --- /dev/null +++ b/Tests/test3.py @@ -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)))