Advertisement
Guest User

Untitled

a guest
Feb 6th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.87 KB | None | 0 0
  1. exists_shorter(Word, List) :-
  2.     member(Another, List),
  3.     length(Another,L1),
  4.     length(Word,L2),
  5.     L1 < L2.
  6.  
  7. /* shortest word */
  8. shortest(List, Word) :-
  9.     member(Word, List),
  10.     not(exists_shorter(Word,List)).
  11.  
  12. /* If two words have common latter */
  13. has_common_letter([First|_], Word2) :- member(First, Word2).
  14. has_common_letter([_|Tail1], Word2) :- has_common_letter(Tail1, Word2).
  15.  
  16. /* If exists Word2 that has no common letters with Word1 */
  17. bad_word(Word1, List) :-
  18.     member(Word2, List),
  19.     not(has_common_letter(Word1,Word2)).
  20.        
  21. filter_words(List, [H|T], [H|T2]) :- not(bad_word(H,List)), !, filter_words(List, T, T2).
  22. filter_words(List, [_|T], T2) :- filter_words(List,T,T2).
  23. filter_words(_,[],[]).
  24.  
  25. filter_pretty(List, Result) :- filter_words(List,List,Result).
  26.  
  27. gee(List,Res) :- filter_pretty(List,Filtered), shortest(Filtered, Res).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement