Created
December 29, 2021 14:07
-
-
Save ppcamp/d047dd190afb5418181266e89b8c9cc0 to your computer and use it in GitHub Desktop.
Pack with some functions in PROLOG lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
append([],L,L):-!. | |
append([H|T1], L, [H|T3]):- append(T1,L,T3). | |
erase(X,L1,L2):- append(A, [X|D], L1), | |
append(A, D, L2). | |
fatorial(0,1):-!. | |
fatorial(N,F):- N1 is N-1, | |
fatorial(N1,F1), | |
F is N*F1. | |
max(X,Y,X):- X>=Y,!. | |
max(_,Y,Y). | |
appendNotRepeated(X,L,L):- in(X,L),!. | |
appendNotRepeated(X,L,[X|L]). | |
in(X,[X|_]):- !. | |
in(X,[_|Y]):- in(X,Y). | |
len([],0):-!. | |
len([_|Y],N):- len(Y,NY), | |
N is NY+1. | |
imprime(1):- write('um'). | |
hr(0):- write('-'),!. | |
hr(N):- write('-'), N1 is N-1, hr(N1). | |
aluno(pedro,20). | |
aluno(carlos,141). | |
aluno(zezin,11). | |
/* findall(X, aluno(X,_), L) Mostra todas as declaracoes no formato lista*/ | |
/* | |
* Common Methods | |
*/ | |
/* | |
* Notes: | |
* O corte vermelho é usado para simular uma condicional | |
* de caso contrário. Dessa forma, ele executa a linha | |
* que esta se for verdade ignorando a segunda | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comprimento([],0). | |
comprimento([_|T],S):- comprimento(T,S1), | |
S is S1+1,!. | |
sigma([],0). | |
sigma([H|T],R):- sigma(T,R1), | |
R is H+R1,!. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nota(joao,2.0). | |
situacao(N,"aprovado"):- nota(N,S), S >= 7,!. | |
situacao(N,"recuperacao"):- nota(N,S), S >= 5, !. | |
situacao(_,"reprovado"). | |
/******************************************************/ | |
pertence(X, [X|_]):- !. | |
pertence(N, [_|L]):- pertence(N,L). | |
uniao([], L, [_|L]). | |
uniao([A|B], C, [A|_]):- | |
not( pertence(A,C) ), | |
uniao(B, C, _). | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment