This file contains hidden or 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
| firstFit(Start, Len, [], Start, [Start-Len]). | |
| firstFit(Start, Len, [Alloc-AllocLen|Rest], Pos, NewTaken) :- | |
| Start + Len =< Alloc -> Pos = Start, NewTaken = [Start-Len,Alloc-AllocLen|Rest]; | |
| NewStart is Alloc + AllocLen, firstFit(NewStart, Len, Rest, Pos, RestTaken), NewTaken = [Alloc-AllocLen|RestTaken]. | |
| merge([], []). | |
| merge([X], [X]). | |
| merge([A-AL, B-BL|Rest], New) :- | |
| B is A + AL -> L is AL + BL, merge([A-L|Rest], New); | |
| merge([B-BL|Rest], RestNew), New = [A-AL|RestNew]. |
This file contains hidden or 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
| zena(vdova). | |
| zena(dcera). | |
| muz(ja). | |
| muz(otec). | |
| muz(syn). | |
| muz(otcuvSyn). | |
| bioRodic(vdova, dcera). | |
| bioRodic(otec, ja). |
This file contains hidden or 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
| natural(0). | |
| natural(s(N)) :- natural(N). | |
| smaller(0, s(_)). | |
| smaller(s(M), s(N)) :- smaller(M, N). | |
| % Predikat postupne generuje dvojice prirozenych cisel X, Y tak, | |
| % ze X < Y. | |
| gen_smaller(X, Y) :- natural(Y), smaller(X, Y). |
This file contains hidden or 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
| % recodex: revize | |
| person(O) :- member(O, [david, thomas, emma, stella]). | |
| across(david, thomas). | |
| across(thomas, david). | |
| across(emma, stella). | |
| across(stella, emma). | |
| distinct(A, B, C, D) :- |
This file contains hidden or 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
| sublist(L, M) :- | |
| M = [_|_], | |
| append(_, Suffix, L), | |
| append(M, _, Suffix). | |
| subseq([], []). | |
| subseq([X|L], [X|M]) :- subseq(L, M). | |
| subseq([_|L], M) :- subseq(L, M). | |
| disjoint([], [], []). |
This file contains hidden or 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
| cone([o,o,o], 0). | |
| cone(R, 1) :- select(x, R, [o,o]). | |
| cone(R, 2) :- select(o, R, [x,x]). | |
| cone([x,x,x], 3). | |
| match([_,_], []). | |
| match([A,B,C|R], [M|RM]) :- cone([A,B,C],M), match([B,C|R], RM). | |
| miny(Pocty, Miny) :- same_length(Pocty, Miny), append([[o],Miny,[o]], MinyLong), match(MinyLong, Pocty). |
This file contains hidden or 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
| maptree(_, nil). | |
| maptree(P, b(L, X, R)) :- | |
| call(P, X), maptree(P, L), maptree(P, R). | |
| size(nil, 0, -1). | |
| size(b(L, _, R), S, H) :- | |
| SP is S - 1, between(0, SP, SL), SR is S - SL - 1, | |
| HP is H - 1, (HL = HP, between(-1, HP, HR); between(-1, HP, HL), HR = HP, HL \= HR), | |
| size(L, SL, HL), | |
| size(R, SR, HR). |
This file contains hidden or 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
| mark_enter(X, enter(X)). | |
| dfs(_, [], Visited, Visited, Time, Time). | |
| dfs(G, [exit(V)|Vs], Visited, FinalVisited, Time, FinalTime) :- | |
| member(V/_/Time, Visited), NewTime is Time + 1, | |
| dfs(G, Vs, Visited, FinalVisited, NewTime, FinalTime). | |
| dfs(G, [enter(V)|Vs], Visited, FinalVisited, Time, FinalTime) :- | |
| ( member(V/_/_, Visited) -> dfs(G, Vs, Visited, FinalVisited, Time, FinalTime) | |
| ; member(V-Neigh, G), maplist(mark_enter, Neigh, NeighEnter), | |
| NewTime is Time + 1, |
This file contains hidden or 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
| factors_ :: Int -> Int -> [Int] | |
| factors_ p k = | |
| if k * k > p | |
| then [p] | |
| else if p `mod` k == 0 | |
| then k:factors_ (p `div` k) k | |
| else factors_ p (k + 1) | |
| factors :: Int -> [Int] | |
| factors p = factors_ p 2 |
This file contains hidden or 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
| import Data.List | |
| is_equiv :: (a -> a -> Bool) -> [a] -> Bool | |
| is_equiv (~=) set = refl && sym && trans | |
| where | |
| infix 1 ==> | |
| x ==> y = not x || y | |
| every c = all c set |