Skip to content
Snippets Groups Projects
Commit 6fcb7c77 authored by jfschaefer's avatar jfschaefer
Browse files

added my prolog problem stuff

parent 8d551b35
No related branches found
No related tags found
No related merge requests found
Readme
===
AI 1 - 2019/2020
---
* 2019-10-28: `2019-10-28-tutorial.pl` (simple prolog exercises)
% This is the prolog file we created during the tutorial.
%
% Remark: inspired by this problem list: http://www.ic.unicamp.br/~meidanis/courses/mc336/2009s2/prolog/problemas/
% INTRODUCTION
country(germany).
geolocation(X) :- country(X).
bigger(russia, germany).
bigger(germany, belgium).
bigger(A, B) :-
bigger(A, C), bigger(C, B).
% LIST EXERCISES
firstelement([A|_], A).
lastelement([A], A).
lastelement([_|A], B) :-
lastelement(A, B).
secondlast([H,_], H).
secondlast([_|A], B) :-
secondlast(A, B).
second([], []).
second([A], [A]).
second([A,_|B], [A|Restlist]) :-
second(B, Restlist).
prepend(A, B, [A|B]).
duplicate([], []).
duplicate([A], [A,A]).
duplicate([H|T], [H,H|T2]) :-
duplicate(T, T2).
% INSERTION SORT
insert(Element, [], [Element]).
insert(Element, [Hs|Ts], [Element,Hs|Ts]):-
Element =< Hs.
insert(Element, [Hs|Ts], [Hs|Tl]) :-
Element >= Hs,
insert(Element, Ts, Tl).
inssort([], []).
inssort([H|T], Result) :-
inssort(T, X),
insert(H, X, Result).
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment