1 / 8

Umel á inteligencia Cvi čenie 4

Umel á inteligencia Cvi čenie 4. Mgr. Ján Grman Jan.Grman @stuba.sk , KMER www.ui.kmer.elf.stuba.sk. Zoznamy. [1,2,3,4], [1,2,3,4,[2,3]] [Hlava|Telo] L e n(L,X ) dĺžka zoznamu L dlzka([], 0). dlzka([_ | T], N) :-dlzka(T, M),N is 1 + M. :-dlzka([1,2,3,4],Y). [H|T] = [1,2,3,4].

ella
Download Presentation

Umel á inteligencia Cvi čenie 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Umelá inteligenciaCvičenie4 Mgr. Ján Grman Jan.Grman@stuba.sk, KMER www.ui.kmer.elf.stuba.sk

  2. Zoznamy [1,2,3,4], [1,2,3,4,[2,3]] [Hlava|Telo] • Len(L,X) dĺžka zoznamu L • dlzka([], 0). • dlzka([_ | T], N) :-dlzka(T, M),N is 1 + M. • :-dlzka([1,2,3,4],Y). • [H|T] = [1,2,3,4]. • [H,K,L|T] = [1,2,3,4,5,6,7,8]. • pos(A,[],_):-fail.

  3. Zoznamy • cnt(A,L,X) počet prvkov A v zozname L • pos(A,L,X) pozícia prvku A v zozname L • ismember(A, L) je prvok v zozname? • (použitie = a ==) • rev(L,M) obrátený zoznam • delete(A,L,M)vymaže prvok A zo zoznamu L (každý výskyt) • delete1(A,L,M)vymaže prvok A zo zoznamu L (prvý výskyt) • insert (A,L,M) pridá prvok A do zoznamu L • concat(L,M,N) spojí zoznamy L a M

  4. Zoznamy • spoj([],Y,Y). • spoj([H | T],Y,Z):-spoj(T,Y,Q),Z = [H | Q]. • spoj([], X, X). • spoj([H | T1], X, [H | T2]):-spoj(T1, X, T2). • rev([],[]). • rev([H|T],Y):-rev(T,Q),spoj(Q,[H],Y).

  5. Zoznamy a čísla • len_kladne([1,-3,5,7,-1], Y). • Y=[1,5,7] • ine_len_kladne([1,-3,[-2,3],5,7,-1], Y). • Y=[1,[3],5,7]

  6. Zoznamy • qsort(L,Vysl) - rozdeluj a panuj L=[5,3,7,8,1,4,7,6], L=[H|T],H=5 T=[3,7,8,1,4,7,6] divide(5, . . . ) M=[3,1,4], qsort(M) V=[7,8,7,6], qsort(V) M1=[1,3,4] V1=[6,7,7,8] append - M1.[5].V1 Vysl=[1,3,4,5,6,7,7,8]

  7. Rozdel zoznam divide(pivot,zoznam,Z1,Z2) Ak Zoznam=[] potom Z1=[] aj Z2=[]. Ak Zoznam=[H|T] • Ak H je menší rovnýako PIVOT • potom Z1=[H,ZT] • divide(pivot,T,ZT,Z2) • Ak H je väčší ako PIVOT • potom Z2=[H,ZT] • divide(pivot,T,Z1,ZT)

  8. Quicksort • qsort([],[]):-!. • qsort([H],[H]):-!. • qsort([H|T],L):-divide(H,T,M,V),qsort(M,M1),qsort(V,V1),append(M1,[H|V1],L). • divide(_,[],[],[]):-!. • divide(H,[K|T],[K|M],V):-K=<H,!,divide(H,T,M,V). • divide(H,[K|T],M,[K|V]):-K>H,divide(H,T,M,V).

More Related