Last active
March 7, 2025 00:32
-
-
Save vituscze/b53fda3afcada8ae581711bbe7912ddb to your computer and use it in GitHub Desktop.
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) :- | |
| person(A), person(B), person(C), person(D), | |
| A \= B, A \= C, A \= D, B \= C, B \= D, C \= D. | |
| solve(Dumplings, Pasta, Soup, Trout) :- | |
| distinct(Dumplings, Pasta, Soup, Trout), | |
| distinct(Beer, Cider, IcedTea, Wine), | |
| across(Cider, Trout), | |
| Dumplings = Beer, | |
| Soup = Cider, | |
| across(Pasta, Beer), | |
| IcedTea \= david, | |
| Wine = emma, | |
| Dumplings \= stella. | |
| % addBit(A, B, CarryIn, R, CarryOut) | |
| addBit(zero, zero, zero, zero, zero). | |
| addBit(one, zero, zero, one, zero). | |
| addBit(zero, one, zero, one, zero). | |
| addBit(zero, zero, one, one, zero). | |
| addBit(one, one, zero, zero, one). | |
| addBit(one, zero, one, zero, one). | |
| addBit(zero, one, one, zero, one). | |
| addBit(one, one, one, one, one). | |
| add(X3, X2, X1, X0, Y3, Y2, Y1, Y0, Z4, Z3, Z2, Z1, Z0) :- | |
| addBit(X0, Y0, zero, Z0, C0), | |
| addBit(X1, Y1, C0, Z1, C1), | |
| addBit(X2, Y2, C1, Z2, C2), | |
| addBit(X3, Y3, C2, Z3, Z4). | |
| % generovani seznamu dane delky | |
| gen_length([], 0). | |
| gen_length([_|R], N) :- | |
| N > 0, PN is N - 1, gen_length(R, PN). | |
| % proc nefunguje jako gen_length([1,2,3], R)? | |
| :- use_module(library(clpfd)). | |
| gen_length2([], 0). | |
| gen_length2([_|R], N) :- | |
| N #> 0, PN #= N - 1, gen_length2(R, PN). | |
| opposite(left, right). | |
| opposite(right, left). | |
| % minheap - nil, node(Dir, X, L, R) | |
| heap_insert(V, nil, node(left, V, nil, nil)). | |
| heap_insert(V, node(Dir, X, L, R), node(NewDir, NewX, NewL, NewR)) :- | |
| opposite(Dir, NewDir), | |
| (V < X, NewX = V, ToInsert = X; V >= X, NewX = X, ToInsert = V), | |
| (Dir = left, heap_insert(ToInsert, L, NewL), NewR = R; Dir = right, heap_insert(ToInsert, R, NewR), NewL = L). | |
| % korenove stromy | |
| % node(Val, [SubTree1, SubTree2, ..., SubTreeN]) | |
| add_one(_, V, V2) :- V2 is V + 1. | |
| length_foldl(List, L) :- foldl(add_one, List, 0, L). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment