Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Ejercicio 2
- likes('juan', 'ice cream').
- alto('jose').
- travel('juan' 'car').
- eat('juan', 'chocolate').
- eat('juan', 'apples').
- eat('juan', 'cheese').
- root(16, 4).
- root(16, -4).
- country('argentina').
- country('peru').
- country('uruguay').
- % Ejercicio 3
- share_home(X, Y) :- dir(X, Home), dir(Y, Home).
- siblings(X, Y) :- parents(X, Father, Mother), parents(Y, Father, Mother)
- % Ejercicio 6
- head([Head | _], Result) :- Result = Head.
- tail([_ | Tail], Result) :- Result = Tail.
- even(Number) :- 0 =:= Number mod 2.
- odd(Number) :- 0 =\= Number mod 2.
- % Ejercicio del parcial
- un_entero([], []).
- un_entero([H|T], ListaEnteros) :- Siguiente is H+1, un_entero(T, EnterosAnteriores), append([Siguiente], EnterosAnteriores, ListaEnteros).
- % Otra forma de hacer el ejercicio del parcial
- un_entero2([], []).
- un_entero2([H|T], [H2|T2]) :- H2 is H + 1, un_entero2(T, T2).
- % Factorial de un número (horriblemente ineficiente, falta memoización)
- factorial(0, 1).
- factorial(X, Y) :- Anterior is X - 1, factorial(Anterior, Resultado), Y is X * Resultado.
- % Fibonacci (horriblemente ineficiente, igual que el anterior)
- fibonacci(0, 1).
- fibonacci(1, 1).
- fibonacci(N, Resultado) :- Ant1 is N - 1, Ant2 is N - 2, fibonacci(Ant1, Res1), fibonacci(Ant2, Res2), Resultado is Res1 + Res2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement