tout_formule_loi.py

Created by joelkouakou2080

Created on December 21, 2023

642 Bytes


% Règle pour calculer la factorielle d'un nombre
factorielle(0, 1). % Cas de base : la factorielle de 0 est 1
factorielle(N, Resultat) :-
    N > 0,
    N1 is N - 1,
    factorielle(N1, SubResultat),
    Resultat is N * SubResultat.

?- factorielle(5, X).
% X = 120



% Règle pour calculer le n-ème terme de la suite de Fibonacci
fibonacci(0, 0). % Cas de base : le terme 0 est 0
fibonacci(1, 1). % Cas de base : le terme 1 est 1
fibonacci(N, Resultat) :-
    N > 1,
    N1 is N - 1,
    N2 is N - 2,
    fibonacci(N1, Term1),
    fibonacci(N2, Term2),
    Resultat is Term1 + Term2.

?- fibonacci(7, X).
% X = 13

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.