# Prolog code dating service

*22-Nov-2019 12:42*

You should also indicate the intended data types of the arguments and the allowed flow patterns. Problems marked with two asterisks (**) are of intermediate difficulty. X = [a, b, c, d, e] Hint: Use the predefined predicates is_list/1 and append/3 If a list contains repeated elements they should be replaced with a single copy of the element. As in problem P11, simplify the result list by replacing the singleton terms [1, X] by X. The objective is to sort the elements of In List according to their length. short lists first, longer lists later, or vice versa. - lsort(o], [d, e], [d, e], [m, n], [a, b, c], [f, g, h], [i, j, k, l b) Again, we suppose that a list (In List) contains elements that are lists themselves.If you are a skilled Prolog programmer it shouldn't take you more than 30-90 minutes to solve them. Transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). But this time the objective is to sort the elements of In List according to their length frequency; i.e.In level H, which may contain less than the maximum possible number of nodes, all the nodes are "left-adjusted".This means that in a levelorder tree traversal all internal nodes come first, the leaves come second, and empty successors (the nil's which are not really nodes! Particularly, complete binary trees are used as data structures (or addressing schemes) for heaps.We can assign an address number to each node in a complete binary tree by enumerating the nodes in levelorder, starting at the root with number 1.In doing so, we realize that for every node X with address A the following property holds: The address of X's left and right successors are 2*A and 2*A 1, respectively, supposed the successors do exist.

||You should also indicate the intended data types of the arguments and the allowed flow patterns. Problems marked with two asterisks (**) are of intermediate difficulty. X = [a, b, c, d, e] Hint: Use the predefined predicates is_list/1 and append/3 If a list contains repeated elements they should be replaced with a single copy of the element. As in problem P11, simplify the result list by replacing the singleton terms [1, X] by X. The objective is to sort the elements of In List according to their length. short lists first, longer lists later, or vice versa. - lsort(a,b,c],[d,e],[f,g,h],[d,e],[i,j,k,l],[m,n],[o, L). L = o], [d, e], [d, e], [m, n], [a, b, c], [f, g, h], [i, j, k, l b) Again, we suppose that a list (In List) contains elements that are lists themselves.

If you are a skilled Prolog programmer it shouldn't take you more than 30-90 minutes to solve them. Transform a list, possibly holding lists as elements into a `flat' list by replacing each list with its elements (recursively). But this time the objective is to sort the elements of In List according to their length frequency; i.e.

]]% atlevel(T, L, S) :- S is the list of nodes of the binary tree T at level L Using atlevel/3 it is easy to construct a predicate levelorder/2 which creates the level-order sequence of the nodes. binary tree with height H is defined as follows: The levels 1,2,3,..., H-1 contain the maximum number of nodes (i.e 2**(i-1) at the level i, note that we start counting the levels from 1 at the root).

Write a predicate internals/2 to collect them in a list.

% internals(T, S) :- S is the list of internal nodes of the binary tree T.

We are only interested in the structure, not in the contents of the nodes. T = t(3, t(2, t(1, nil, nil), nil), t(5, nil, t(7, nil, nil))) Then use this predicate to test the solution of the problem P56. What is the maximum number of nodes it can contain? ) Now, we can attack the main problem: construct all the height-balanced binary trees with a given nuber of nodes.

Use the predicate add/3, developed in chapter 4 of the course, to write a predicate to construct a binary search tree from a list of integer numbers. % hbal_tree_nodes(N, T) :- T is a height-balanced binary tree with N nodes.

It has been confirmed up to very large numbers (much larger than we can go with our Prolog system). L = [5,23] Given a range of integers by its lower and upper limit, print a list of all even numbers and their Goldbach composition. Very rarely, the primes are both bigger than say 50. 992 = = 61 1321 1856 = 67 1789 1928 = 61 1867 Define predicates and/2, or/2, nand/2, nor/2, xor/2, impl/2 and equ/2 (for logical equivalence) which succeed or fail according to the result of their respective operations; e.g.