Prolog Recursion skipping same results

前端 未结 3 972
余生分开走
余生分开走 2020-12-04 02:28

My code runs but the problem is it shows the same results more than once. Here\'s my code:

disease(hiv,[sore_throat,headache,fever,rash]).
disease(pregnancy         


        
3条回答
  •  Happy的楠姐
    2020-12-04 03:08

    Alternatively, you can write :

    disease(hiv,[sore_throat,headache,fever,rash]).
    disease(pregnancy,[fatigue,vomiting,light_headedness,increased_waistline]).
    disease(flu,[fatigue,fever,tiredness,nasal_discharge]).
    
    diagnose(Name, Symptoms) :-
        findall(D, (disease(D, S), intersection(S, Symptoms, I), I \== []), MayGot),
        atomic_concat(Name, ' has/is ', Start),
        maplist(atomic_concat(Start), MayGot, Temp),
        maplist(writeln, Temp).
    

    But if you're trying to learn Prolog it's not a good idea since it's more functionnal and less Prolog-ish, thought I'd mention this possibility anyway !

提交回复
热议问题