

P2_03.pl % 2.03 (**) Determine the prime factors of a given positive integer (2). Lfsort (L ,LFS ), write ( 'LFS = ' ), write (LFS ), nl. Lsort (L ,LSD ,desc ), write ( 'LSD = ' ), write (LSD ), nl , Lsort (L ,LS ), write ( 'LS = ' ), write (LS ), nl , Transf (L -_, ,Ys, ) :- transf (L -X ,Xs ,Ys ,Zs ). % transf(L-X,Xs,Ys,Z) Ys is the list that remains from the list Xs % when all leading copies of length L are removed and transfed to Z Pack (, |Zs ] ) :- transf (L -X ,Xs ,Ys ,Z ), pack (Ys ,Zs ). % sorting direction Dir is either asc or desc Lfsort (InList ,OutList ) :- lfsort (InList ,OutList ,asc ).

And finally, the last % three lists have length 2. The third and forth list have length 3 which % appears, there are two list of this length.

% L =, ,, ,, , ] % % Note that the first two lists in the Result have length 4 and 1, both % length appear just once. in the default, % where sorting is done ascendingly, lists with rare lengths are placed % first, other with more frequent lengths come later. Then OutList is obtained from InList by sorting % its elements according to their length frequency i.e. % b) length frequency sort % % lfsort (InList,OutList) :- it is supposed that the elements of InList % are lists themselves. Length (X ,L1 ), L is -L1, add_key (Xs ,Ys ,desc ). % sorting direction Dir is either asc or descĪdd_key (, ,asc ) :- ! , Lsort (InList ,OutList ) :- lsort (InList ,OutList ,asc ). lsort/2 sorts ascendingly, % lsort/3 allows for ascending or descending sorts. Then OutList is obtained from InList by sorting % its elements according to their length. P1_28.pl % 1.28 (**) Sorting a list of lists according to length % % a) length sort % % lsort(InList,OutList) :- it is supposed that the elements of InList % are lists themselves. % The group sizes are given in the list Ns. % subtract/3 is predefined % Problem b): Generalization % group(G,Ns,Gs) :- distribute the elements of G into the groups Gs. after generating S = do not return % S =, etc.Įl (X, ,R ) :- el (X ,L ,R ). Via backtracking return all posssible selections, but % avoid permutations i.e. % selectN(N,L,S) :- select N elements of the list L and put them in % the set S. % Problem a) % group3(G,G1,G2,G3) :- distribute the 9 elements of G into G1, G2, and G3, % such that G1, G2 and G3 contain 2,3 and 4 elements respectively P1_27.pl % 1.27 (**) Group the elements of a set into disjoint subsets. % In the case of N=1, T is X, instead of the term.
#NINETY NINE KNIGHTS 2 ISO PLUS#
T is the term, % where N is K plus the number of X's that can be removed from Xs. % count(X,Xs,Ys,K,T) Ys is the list that remains from the list Xs % when all leading copies of X are removed. % However, if N equals 1 then the element is simply copied into the % output list. Consecutive duplicates of elements are encoded % as terms, where N is the number of duplicates of the element E. PAGES WILL BE DELETED OTHERWISE IF THEY ARE MISSING BASIC MARKUP.P1_13.pl % 1.13 (**): Run-length encoding of a list (direct solution) % encode_direct(L1,L2) :- the list L2 is obtained from the list L1 by % run-length encoding. DON'T MAKE PAGES MANUALLY UNLESS A TEMPLATE IS BROKEN, AND REPORT IT THAT IS THE CASE. THIS SHOULD BE WORKING NOW, REPORT ANY ISSUES TO Janna2000, SelfCloak or RRabbit42.

The Trope workshop specific templates can then be removed and it will be regarded as a regular trope page after being moved to the Main namespace.
#NINETY NINE KNIGHTS 2 ISO MANUAL#
