For loop untill condition == True - Brute Force

I am trying to solve a diophantine equation using a simple for loop to solve this equation:
f(x,y) = x^2 + y^3 == 31
So i have defined:
X = collect(1:1:10) e Y= collect(1:1:10)
and tried:

for i in Y
    for j in X
          println(i, j, f(i,j))
    end
end

There a True return(2,3) and I want to get the X and Y of this True return and not all the false results…but I am not able to do it so far…any tips?

How can i code this?

function solve_equation(f::Function, X, Y)
    for x in X
        for y in Y
            if f(x,y)
                return (x, y)
            end
         end
    end
    println("No solutions found")
end
solve_equation(f, 1:10, 1:10)

Does this do what you want?

4 Likes

yes. Thanks man.

1 Like