Sending All Back too

This commit is contained in:
2019-01-20 00:55:27 +01:00
parent f7636e3abd
commit f02bb52c76
12 changed files with 174 additions and 0 deletions
Vendored
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
from Solver import *
print(solve("2x+5=6"))
BIN
View File
Binary file not shown.
+91
View File
@@ -0,0 +1,91 @@
from set import *
from equation import *
from expression import *
class Solver:
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: "))
BIN
View File
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
class human:
def __init__(self,nom):
self.pieds=2
self.nom=nom
def marcher(self):
print("Yes je marche avec mes "+self.nom+" pieds")
valentin=human("valentin")
valentin.marcher()
+9
View File
@@ -0,0 +1,9 @@
from expression import *
def isolate(equation):
i=equation.index("=")
first_member=equation[:i]
second_member=equation[i+1:]
equation="("+first_member+")-("+second_member+")=0"
print(equation)
return equation
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
def countCharacters(expression,character):
r=0
for i in input:
if i==character:
r+=1
return count
def simplifyParenthesis(expression):
return expression
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
def intersection(list1,list2):
list1=set(list1)
list2=set(list2)
elements=inBoth(list1,list2)
return set(elements)
def union(list1,lis2):
elements=inOne(list1,list2)
return set(elements)
def inOne(list1,list2):
return list1+list2
def inBoth(list1,list2):
in_both=[]
for e1 in list1:
for e2 in list2:
if e1 is e2:
in_both.append(e1)
return in_both
+33
View File
@@ -0,0 +1,33 @@
# import the necessary packages
import numpy as np
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required = True, help = "Numeriser 2.jpeg")
args = vars(ap.parse_args())
# load the image, clone it for output, and then convert it to grayscale
image = cv2.imread(args["image"])
output = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# detect circles in the image
circles = cv2.HoughCircles(gray, cv2.CV_HOUGH_GRADIENT, 1.2, 100)
# 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)