1
示例数据库获得3个值:序言 - 停留在家庭作业 - 使用数据库和输入2倍的值从数据库中
any(a,b,2).
any(b,c,2).
any(c,d,3).
any(d,e,1).
any(e,f,3).
重点:(Station1,Station2,Time)
。
问题:
进入(station1,time)
为序言,并让它触手可及返回所有站。
例如:
如果输入:(b,2)
。
输出应该是:“a”和“C”
这是因为,从“2”分站“B”,你就可以去站“A”和“C”作为他们在输入时间的范围内。
我已经厌倦了使用列表和递归,但没有运气,任何帮助/建议吗?
reachable(Station1, Limit, Result) :-
reachable(Station1, Limit, 0, 0, Result).
reachable(Station1, Visited, TimeSpent, Limit, Result) :-
overground(Station1,Station2,Time),
Visited is Limit - Time,
Limit =< TimeSpent,
Result = [Station2];
overground(Station1, Waypoint, Time),
NewVisited is Visited - Limit,
NewTimeSpent is TimeSpent - NewVisited,
reachable(Waypoint,Station2, NewTimeSpent, NewVisited,Result).
< < <东西,我试过,但似乎没有工作X_X
'c'距'b'3分钟吗? – dasblinkenlight 2011-12-23 01:19:53
将其标记为家庭作业+1。 – xQbert 2011-12-23 01:30:04
噢是的,提出了一个数据库输入错误 – daydream 2011-12-23 01:35:49