Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Ejercicios de Prolog sobre números

Ejercicios de Prolog sobre números 2 months 3 weeks ago #8258

  • kirstein
  • kirstein's Avatar Topic Author
  • Offline
  • Profesor
  • Profesor
  • Posts: 2347
  • Karma: 666
  • Thank you received: 1316
Hola,

+ Estos son las relaciones numéricas.

Saludos,
Kirstein
domains
   listaNum = integer*
    

predicates

   alapar(integer,integer).
   
   menor(integer,integer).
   
   menorBi(integer,integer).
   
   odd(integer).
   even(integer).
   
   primo(integer).
   primoAux(integer,integer).
   
   listaPrimos(integer,listaNum).
   listaFib(integer,listaNum).
   
   fibonaccip(integer).
   fibonacci(integer,integer).
   
   fiboAux(integer,integer,integer,integer,integer).
   
clauses

   alapar(X,Y):- bound(Y), X = Y + 1.
   alapar(X,Y):- bound(Y), X = Y - 1.
   alapar(X,Y):- bound(X), Y = X + 1.
   alapar(X,Y):- bound(X), Y = X - 1.
   
   fibonaccip(N):- fibonacci(_,N).

   fibonacci(0,1).
   fibonacci(1,1).
   fibonacci(N,X):- bound(N), !, N>1, fiboAux(2,1,1,N,X).
   fibonacci(N,X):- fiboAux(2,1,1,N,X),N>1.
   
   fiboAux(N,Ult,Pen,N,X):- X = Ult + Pen,!.                    
   fiboAux(I,Ult,Pen,N,X):- I2 = I + 1,
                            bound(N),
                            I < N, 
                            New = Ult + Pen,
                            fiboAux(I2,New,Ult,N,X).                      
   fiboAux(I,Ult,Pen,N,X):- bound(X),
                            I2 = I + 1,
                            New = Ult + Pen,
                            New < X,
                            fiboAux(I2,New,Ult,N,X).                      
                    
   
   
   
   menor(A,B):- A<B.

   menorBi(A,B):- A<B.
   menorBi(A,B):- B<A.
   
   odd(X):- X mod 2 = 1.
   even(X):- not(odd(X)).
   
   
   primo(X):- primoAux(X,2).
   
   primoAux(X,N):- N > X div 2,!.
   primoAux(X,N):- X mod N <> 0,
                   N2 = N + 1,
                   primoAux(X,N2).
                   
   listaPrimos(0,[]).
   listaPrimos(N,[N|Cdr]):- primo(N),
                            N2 = N - 1,
                            listaPrimos(N2,Cdr),!. 
   listaPrimos(N,Otros):- N2 = N - 1,
                          N2>0,
                          listaPrimos(N2,Otros). 


   listaFib(0,[]).
   listaFib(N,[N|Cdr]):- fibonaccip(N),
                            N2 = N - 1,
                            listaFib(N2,Cdr),!. 
   listaFib(N,Otros):- N2 = N - 1,
                          listaFib(N2,Otros). 
   

Please Identificarse to join the conversation.

  • Page:
  • 1
  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to add attachements.
  • Not Allowed: to edit your message.
Time to create page: 0.121 seconds
Powered by Kunena Forum