Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Prolog examples using TuProlog


1. Prolog examples using TuProlog

2. TuProlog
For installation and use of TuProlog, see tuprolog .

TuProlog can be used in interactive mode and also to run Prolog scripts in a batch-oriented way. For more info, see the TuProlog manual (in PDF form).

3. Interactive shell
The following command can be used to experiment with the interactive Prolog shell using TuProlog.

Note: This assumes that Java is installed and that TuProlog is installed in the users home directory under the bin folder.
java -cp ~/bin/2p.jar alice.tuprologx.ide.CUIConsole


4. Hello world
Here is the Prolog code.

Here is the output of the Prolog code.


5. Towers of Hanoi
Here is the Prolog code.

Here is the output of the Prolog code.


6. Puzzles
Prolog can be used to solve puzzles involving permutations and combinations.

7. Selection with repetition
The following does a selection allowing repetition.

Here is the Prolog code.

The number of selections with repetition of n objects is n to the power of n. For n = 3 this is 3*3*3 = 27.

Here is the output of the Prolog code.


8. Permutations
A permutation is a selection from a set without repetitions allowed and where order is important.

Here is the Prolog code.

The number of permutations of n objects is n! (n factorial). For n = 3 this is 3*2*1 = 6.

Here is the output of the Prolog code.


9. End of page