Prolog    up
 
 


  Factorial   Michael Neumann
Calculate the factorial

fak(0,1).
fak(N,R) :-  N > 0,  M is N - 1,  fak(M,R1),  R is N * R1.

?- fak(6,N).
Calculates the factorial. Results N = 720


 Finite Domain Constraint Programming   Michael Neumann
solve(A, B, C, D, E, F, G, H, I) :-
  (
    between(1,9,A),
    between(1,9,B), B =\= A,
    between(1,9,C), C =\= B, C =\= A,
    between(1,9,D), D =\= C, D =\= B, D =\= A,
    between(1,9,E), E =\= D, E =\= C, E =\= B, E =\= A,
    between(1,9,F), F =\= E, F =\= D, F =\= C, F =\= B, F =\= A,
    between(1,9,G), G =\= F, G =\= E, G =\= D, G =\= C, G =\= B, G =\= A,
    between(1,9,H), H =\= G, H =\= F, H =\= E, H =\= D, H =\= C, H =\= B, H =\= A,
    between(1,9,I), I =\= H, I =\= G, I =\= F, I =\= E, I =\= D, I =\= C, I =\= B, I =\= A,
    A + B + G =:= 15,
    C + D + H =:= 15,
    E + F + I =:= 15,
    G + H + I =:= 15,

    A + B + C + D + E + F =:= 30
  ).


/* 
  Call it from the Prolog command prompt as follows:

   ?- solve(A, B, C, D, E, F, G, H, I).
*/
The problem: Each questionmark represents a number from 1 to 9 (no two questionmarks may have the same number). Choose the numbers so that the sum of each triangle in the picture below is 15 and the sum of all numbers on the circle is 30.



 Hello World   Michael Neumann
?- write('Hello World'), nl.
Prints "Hello World" onto the screen.