Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exists_shorter(Word, List) :-
- member(Another, List),
- length(Another,L1),
- length(Word,L2),
- L1 < L2.
- /* shortest word */
- shortest(List, Word) :-
- member(Word, List),
- not(exists_shorter(Word,List)).
- /* If two words have common latter */
- has_common_letter([First|_], Word2) :- member(First, Word2).
- has_common_letter([_|Tail1], Word2) :- has_common_letter(Tail1, Word2).
- /* If exists Word2 that has no common letters with Word1 */
- bad_word(Word1, List) :-
- member(Word2, List),
- not(has_common_letter(Word1,Word2)).
- filter_words(List, [H|T], [H|T2]) :- not(bad_word(H,List)), !, filter_words(List, T, T2).
- filter_words(List, [_|T], T2) :- filter_words(List,T,T2).
- filter_words(_,[],[]).
- filter_pretty(List, Result) :- filter_words(List,List,Result).
- gee(List,Res) :- filter_pretty(List,Filtered), shortest(Filtered, Res).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement