Write a prolog script to color the map of continental (excluding islands) South
ID: 3824772 • Letter: W
Question
Write a prolog script to color the map of continental (excluding islands) South America.
Use different colors than these, 4 colors total. No adjacent countries may have the same color.
Submit a script here, and a screenshot of you running a test query.
Note: Use underscores for countries with two words in their names.
Trinidad and Tobago Venezuela Guyana French Guiana Colombia Ecuador Suriname Peru Brazil Bolivia South Pacific Ocean Paragu Chile Argentina Uruguay South Atlantic Ocean Falkland IslandsExplanation / Answer
adjacent(X,Y,Map) :- member([X,Y],Map) ; member([Y,X],Map). find_regions([],R,R). find_regions([[X,Y]|S], R,A) :- (member(X,R) -> (member(Y,R) -> find_regions(S,R,A) ; find_regions(S,[Y|R],A)) ; (member(Y,R) -> find_regions(S,[X|R],A) ; find_regions(S,[X,Y|R],A) ) ). color(Map,Colors,Coloring) :- find_regions(Map,[],Regions), color_all(Regions,Colors,Coloring), + conflict(Map,Coloring). color_all([R|Rs],Colors,[[R,C]|A]) :- member(C,Colors), color_all(Rs,Colors,A). color_all([],_,[]). conflict(Map,Coloring) :- member([R1,C],Coloring), member([R2,C],Coloring), adjacent(R1,R2,Map). map1([[1,2],[1,3],[1,4],[1,5],[2,3],[2,4],[3,4],[4,5]] ).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.