Turbo Prolog
Turbo Prolog
Turbo Prolog
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
* Program 55 */<br />
domains<br />
loc = right ; middle ; left<br />
predicates<br />
hanoi(integer)<br />
move(integer,loc,loc,loc)<br />
inform(loc,loc)<br />
clauses<br />
hanoi(N) :- move(N,left,middle,right).<br />
move(1,A,_,C) :- inform(A,C),!.<br />
move (N , A, B, C) :<br />
N1=N-1,move(N1,A,C,B),inform(A,C),move(N1,B,A,C).<br />
inform(Loc1,Loc2):write("\nMove<br />
a disk from I,Loc1," to ",Loc2).<br />
To solve Towers Of Hanoi with three disks, we give the goal<br />
hanoi(3).<br />
The output is:<br />
Move a disk from left to right<br />
Move a disk from left to middle<br />
Move a disk from right to middle<br />
Move a disk from left to right<br />
Move a disk from middle to left<br />
Move a disk from middle to right<br />
Move a disk from left to right<br />
DIVISION OF WORDS INTO SYLLABLES<br />
A computer program can decide how to divide words into syllables using a very simple<br />
algorithm, which involves looking at the sequence of vowels and consonants each word<br />
contains. For instance, consider the two sequences below:<br />
I. vowel consonant vowel<br />
In this case, the word is divided after the first vowel. For example, this rule can be<br />
applied to the following words:<br />
ruler<br />
prolog<br />
) ru-ler<br />
) pro-log<br />
2. vowel consonant consonant vowel<br />
In this case, the word is divided between the two consonants. For example:<br />
number<br />
anger<br />
) num-ber<br />
) an-ger<br />
These two rules work well for most words, but fail with words like handbook, which<br />
conform to neither pattern. To divide such words, our program would have to use a<br />
library containing all words.<br />
118 <strong>Turbo</strong> <strong>Prolog</strong> Owner's Handbook