Advertisement
ganryu

Untitled

Nov 20th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.29 KB | None | 0 0
  1. % Ejercicio 2
  2. likes('juan', 'ice cream').
  3.  
  4. alto('jose').
  5.  
  6. travel('juan' 'car').
  7.  
  8. eat('juan', 'chocolate').
  9. eat('juan', 'apples').
  10. eat('juan', 'cheese').
  11.  
  12. root(16, 4).
  13. root(16, -4).
  14.  
  15. country('argentina').
  16. country('peru').
  17. country('uruguay').
  18.  
  19. % Ejercicio 3
  20. share_home(X, Y) :- dir(X, Home), dir(Y, Home).
  21. siblings(X, Y) :- parents(X, Father, Mother), parents(Y, Father, Mother)
  22.  
  23. % Ejercicio 6
  24. head([Head | _], Result) :- Result = Head.
  25. tail([_ | Tail], Result) :- Result = Tail.
  26. even(Number) :- 0 =:= Number mod 2.
  27. odd(Number) :- 0 =\= Number mod 2.
  28.  
  29. % Ejercicio del parcial
  30. un_entero([], []).
  31. un_entero([H|T], ListaEnteros) :- Siguiente is H+1, un_entero(T, EnterosAnteriores), append([Siguiente], EnterosAnteriores, ListaEnteros).
  32.  
  33. % Otra forma de hacer el ejercicio del parcial
  34. un_entero2([], []).
  35. un_entero2([H|T], [H2|T2]) :- H2 is H + 1, un_entero2(T, T2).
  36.  
  37. % Factorial de un número (horriblemente ineficiente, falta memoización)
  38. factorial(0, 1).
  39. factorial(X, Y) :- Anterior is X - 1, factorial(Anterior, Resultado), Y is X * Resultado.
  40.  
  41. % Fibonacci (horriblemente ineficiente, igual que el anterior)
  42. fibonacci(0, 1).
  43. fibonacci(1, 1).
  44. 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