-1

I'm doing some exercises to learn Prolog programming. However, I can't figure out how to do this: I need to solve this equation with a prolog program (click here).

The code I already wrote: solveQuadratic([], []). solveQuadratic([a,b,c], Result) :-

The 'Result' has to be a list with 2,1 or 0 elements that shows the zero points of this equation.

Thank you!

  • 2
    why do you state `solveQuadratic([],[])`, why do you use lowercase constants `[a,b,c]`. Please show some effort and ask specific questions on what is not working. – Willem Van Onsem Sep 17 '17 at 08:52
  • I just don't know what to do – Meal App Sep 17 '17 at 09:06
  • 1
    in case you do not know what to do, you can first aim to solve more basic Prolog questions (by following a tutorial for instance). Or you can first aim to implement the problem in another programming language. – Willem Van Onsem Sep 17 '17 at 09:17
  • Possible duplicate of https://stackoverflow.com/q/25356094/502187 –  Feb 14 '19 at 13:22

1 Answers1

0

I'm a prolog newbie myself and I don't know if I could even solve this question, but I think it would be good for you to consider this:

The result is either a list with 2, 1 or 0 results right? In what cases might we have which amount of results then? The answer lies in the formula: say the part under the root b^2-4ac (I'll call it D) is a negative number (<0), then there would not be an answer, because negative numbers don't have a root. If D is equal to 0. there would only be one answer and if D is greater than 0, the formula would have 2 answers.

I hope this gives you a nudge in the right direction. If you ever solve it, please let me know because I would really like to know the answer myself!

Rose
  • 109
  • 4