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
appendlist([], X, [X]). | |
appendlist([H|T], X, [H|T1]) :- appendlist(T, X, T1). | |
reverse_list([], []). | |
reverse_list([X], [X]). | |
reverse_list([X|T1], L) :- reverse_list(T1, T2), appendlist(T2, X, L),!. |
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
appendlist([], X, [X]). | |
appendlist([H|T], X, [H|T1]) :- appendlist(T, X, T1). | |
palindrome([]). | |
palindrome([X]). | |
palindrome([X|T]) :- appendlist(L, X, T), palindrome(L). |
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
fib(0, 0). | |
fib(1, 1). | |
fib(X, Y) :- X>1, X1 is X - 1, X2 is X - 2, fib(X1, Y1), fib(X2, Y2), Y is Y1 + Y2. |
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
compress([X|[]], [X]). | |
compress([X|[X|Z]], L) :- compress([X|Z], L),!. | |
compress([X|[Y|Z]], [X|L]) :- compress([Y|Z], L),!. |
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
dupli([], []). | |
dupli([X], [X, X]). | |
dupli([H|T], [H, H|L]) :- dupli(T, L), !. |
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
appendlist([], X, X). | |
appendlist([H|T], L1, [H|L2]) :- appendlist(T, L1, L2). | |
dupli([], M, []) :-!. | |
dupli([X], 1, [X]) :-!. | |
dupli([X], M, [X|L]) :- N is M - 1, dupli([X], N, L), !. | |
dupli([H|T], M, L1) :- dupli([H], M, H1), dupli(T, M, T1), appendlist(H1, T1, L1), !. |
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
length_list([], 0). | |
length_list([H|T], X) :- length_list(T, X1), X is X1+1, !. | |
split_list([X|Y], 1, [X], Y). | |
split_list([H|T], M, [H|L1], L2) :- split_list(T, M1, L1, L2), M is M1+1. |
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
fact(0, 1). | |
fact(X, Y) :- X>0, X1 is X-1, fact(X1, Y1), Y is X*Y1. |
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
sumofdigits(X, X) :- X<10. | |
sumofdigits(X, Y) :- X>=10, X1 is X // 10, X2 is X mod 10, sumofdigits(X1, Y1), Y is Y1 + X2. |
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
findmin([X], X). | |
findmin([H|T], X) :- findmin(T, X), H >= X, !. | |
findmin([H|T], H) :- findmin(T, X), H < X, !. |