Reference no: EM132252877
This is the question:
Numerous engineering and scientific applications require finding solutions to a set of equations. Ex: 8x + 7y = 38 and 3x - 5y = -1 have a solution x = 3, y = 2. Given integer coefficients of two linear equations in variables x and y, use brute force to find an integer solution for x and y in the range -10 to 10.
Ex: If the input is:
8 7 38
3 -5 -1
then the output is:
3 2
Use this brute force approach:
xSolution = -99
For every value of x from -10 to 10
For every value of y from -10 to 10
Check if the current x and y satisfy both equations. If so, output the solution, and
assign xSolution with x.
Check if xSolution is still -99. If so, then output "No solution".
Ex: If no solution is found, output:
No solution
The answer can be in Python. I am seriously stuck. No clue. Here's what I have.
integer xSolution
integer x
integer y
xSolution = -99
x = Get next input
y = Get next input
while x >= -10 and x <= 10
while y >= -10 and y <= 10
if 8 * x + 7 * y == 38 and 3 * x - 5 * y == -1
xSolution = x
if xSolution != -99
Put xSolution to output
y = Get next input
elseif xSolution == -99
Put "No solution" to output