Advertisement
aidan-m

Untitled

Sep 25th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.29 KB | None | 0 0
  1. % Base case when MaxDist is 0 and the current article is related to AI
  2. collabDistWithAI(Author, Author, 0, at_least_one) :-
  3.     articleAuthor(Article, Author),
  4.     articleTopic(Article, artificial_intelligence).
  5.  
  6. % Base case for when last chance to find article related to AI
  7. collabDistWithAI(Author1, Author2, 1, at_least_one) :-
  8.     articleAuthor(Article, Author1),
  9.     articleAuthor(Article, Author2),
  10.     articleTopic(Article, artificial_intelligence).
  11.  
  12. % Recursive call when the current article is not related to AI, continue search for AI article
  13. collabDistWithAI(Author1, Author2, MaxDist, at_least_one) :-
  14.     MaxDist > 0,
  15.     Author1 \= Author2,
  16.     articleAuthor(Article1, Author1),
  17.     articleAuthor(Article2, Author2),
  18.     not articleTopic(Article, artificial_intelligence),
  19.     NewMaxDist is MaxDist - 1,
  20.     collabDistWithAI(Author1, Author2, NewMaxDist, at_least_one).
  21.  
  22. % Recursive call when the current article is AI-related, no longer need to search for AI article
  23. collabDistWithAI(Author1, Author2, MaxDist, at_least_one) :-
  24.     MaxDist > 0,
  25.     Author1 \= Author2,
  26.     articleAuthor(Article1, Author1),
  27.     articleAuthor(Article2, Author2),
  28.     articleTopic(Article1, artificial_intelligence),
  29.     NewMaxDist is MaxDist - 1,
  30.     collabDist(Author1, Author2, NewMaxDist).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement