6. Hanoi in Java
public class Test {
private static void emitStep(int source, int dest) {
System.out.println(source + " -> " + dest);
}
static class Step {
Step(int n, int s, int d, int t) {
this.n = n;
source = s;
dest = d;
temp = t;
}
int n, source, dest, temp;
}
private static void hanoi(int n, int source, int dest, int temp) {
java.util.Stack<Step> steps = new java.util.Stack<Step>();
steps.add(new Step(n, source, dest, temp));
while (steps.empty() == false) {
Step step = steps.pop();
if (step.n == 1) {
emitStep(step.source, step.dest);
continue;
}
steps.push(new Step(step.n - 1, step.temp, step.dest, step.source));
steps.push(new Step(1, step.source, step.dest, 0));
steps.push(new Step(step.n - 1, step.source, step.temp, step.dest));
}
}
public static void main(String[] args) {
hanoi(3, 1, 3, 2);
}
}
7. Hanoi in Prolog
move(1,X,Y,_):-
write('Move top disk from '),write(X),write(' to '), write(Y), nl.
move(N,X,Y,Z):-
N>1,M is N-1,move(M,X,Z,Y),move(1,X,Y,_),move(M,Z,Y,X).
30 行 2
行
20. 组织 和会议
ALP(Association for Logic Programming)
逻辑编程协会
http://www.logicprogramming.org/
ICLP(International Conference on Logic
Programming)
逻辑编程国际会议
http://www.iclp2014.net/ Shanghai, China, Oct, 2014.
21. 学习书 籍
入门
"Programming In Prolog". William F. Clocksin and
Christopher S. Mellish. Springer-Verlag, 2003 (5th ed).
"Prolog Programming for Artificial Intelligence". Ivan Bratko.
Addison-Wesley, 2001 (3rd ed).
高级
"The Art of Prolog: Advanced Programming Techniques".
Leon Sterling and Ehud Shapiro. MIT Press, 1994 (2nd ed).
"The Craft of Prolog". Richard A. O'Keefe. MIT Press, 1990.
22. 在线资 料
笨办 法学 Prolog by 泰安小码农 — 轻 松入门
—
http://fengdidi.github.com/blog/2011/11/15/di-0zhang-wei-
shi-yao-yao-xue-xi-prolog/
Adventure in Prolog by Amzi! Inc. —— 语 法大全
http://www.amzi.com/AdventureInProlog/advfrtop.htm
prolog :- tutorial by J.R.Fisher —— 经 典实 例
http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/c
ontents.html
23. 相关 文献
Visual Prolog 的搜索控制机制分析 , 雷英杰 , 王宝树 , 赵晔 ,
王涛,计算机科学, 2005 Vol.32
基于 Prolog 的某型直升机故障诊断专家系统的研究 , 刘卓,
南京大学, 2012
一个动物识别专家系统在 PROLOG 下的实现,夏明华,成
都信息工程学院学报, 2003 Vol.18
Use of Prolog for developing a new programming
language, JL Armstrong, SR Virding, MC Williams - C.
Moss and, 1992