Visual Prolog - Hanoi Example

Hanoi Example

In the 'Towers of Hanoi' example, the Prolog inference engine figures out how to move a stack of any number of progressively smaller disks, one at a time, from the left ('left') pole to the right pole ('right') in the described way, by means of a center ('center') pole as transit, so that there's never a bigger disk on top of a smaller disk. The predicate 'hanoi' takes an integer = the number of disks, as an initial argument. In real-life, Visual Prolog is especially suited for intricate problems, such as resource planning, etc. As the example shows, Visual Prolog can be used for quick 'programming in the small,' but it is mostly employed for industrial-strength large applications.

class hanoi predicates hanoi : (unsigned N). end class hanoi implement hanoi domains pole = string. clauses hanoi(N) :- move(N, "left", "centre", "right"). class predicates move : (unsigned N, pole A, pole B, pole C). clauses move(0, _, _, _) :- !. move(N, A, B, C) :- move(N-1, A, C, B), stdio::writef("move a disc from % pole to the % pole\n", A, C), move(N-1, B, A, C). end implement hanoi goal console::init, hanoi::hanoi(4).

Read more about this topic:  Visual Prolog