字体:
Is there any PROLOG high hand, how can i do this with recursive loop or with list? [#4010807@0 -ROLIA.NET 相约加拿大网上社区 之 枫下论坛 & 枫下部落, 枫下论坛主坛 ]

Is there any PROLOG high hand, how can i do this with recursive loop or with list?

by redspider (红蜘蛛) at 2007.10.23 15:11 (#4010807@0)
neighbor(city1, city2).
neighbor(city2, city3).
neighbor(city3, city4).
neighbor(city4, city5).

to find two neighbors:

neighbors(C1, C2) :- neighbor(C1, C2).
neighbors(C1, C2) :- neighbor(C2, C1).

now what about find out all cities nearby from east to west, ex.

find_nearby_city(city3, X) :- ?????

the output should be:

X = city4; city2; city5; city1; no.

any help apreciated!

该话题已在历史区内,不能被修改或回复。       收藏    投诉
关闭窗口