I could not solve this challenging problem:
name(jack, math, 50).
name(daniel, math, 60).
name(jane, phys, 70).
name(eto, comp, 73).
predicate : nameGrade(P, L, S). P is the list of people who are taking lesson L and whose grade is greater than S.
nameGrade([jack], math, 45). returns true
nameGrade([jack, daniel], math, 55). returns false. (because jack scored 50 which is less than 55)
nameGrade([], phys, 80). returns true
nameGrade(X, math, 70). returns X=[jack, daniel]
nameGrade([jack, daniel], math, X). returns X=50. (the less one).
Thank you.
You can use
findall/3to return a list of elements satisfying a predicate:However, there are some contradictory goals in your requirement. For example,
nameGrade([jack], math, 45)should fail because bothjackanddanieltakemathand have higher scores than45.nameGrade(X, math, 70)should return[]because no one takesmathwith a higher score than70.