Prolog "sequence"
Admin User, erstellt 16. Feb. 2025
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
runner_file(calculate, sequence, 'XLOG 1.4 sequence').
/****************************************************************/
/* Solution Counting */
/****************************************************************/
/* limit(N, G) */
runner_pred(limit,2, calculate, sequence, 'XLOG 1.4.1').
runner_case(limit,2, calculate, sequence, 'XLOG 1.4.1, XLOG 1') :-
findall(X, limit(3, between(5, 10, X)), L),
L == [5,6,7].
runner_case(limit,2, calculate, sequence, 'XLOG 1.4.1, XLOG 2') :-
findall(X, limit(3, between(5, 6, X)), L),
L == [5,6].
runner_case(limit,2, calculate, sequence, 'XLOG 1.4.1, XLOG 3') :-
\+ limit(0, repeat).
runner_case(limit,2, calculate, sequence, 'XLOG 1.4.1, XLOG 4') :-
catch(limit(_,_), error(E,_), true),
E == instantiation_error.
/* offset(N, G) */
runner_pred(offset,2, calculate, sequence, 'XLOG 1.4.2').
runner_case(offset,2, calculate, sequence, 'XLOG 1.4.2, XLOG 1') :-
findall(X, offset(3, between(5, 10, X)), L),
L == [8,9,10].
runner_case(offset,2, calculate, sequence, 'XLOG 1.4.2, XLOG 2') :-
\+ offset(3, between(5, 6, _)).
runner_case(offset,2, calculate, sequence, 'XLOG 1.4.2, XLOG 3') :-
findall(X, limit(5, offset(3, between(1, 10, X))), L),
L == [4,5,6,7,8].
runner_case(offset,2, calculate, sequence, 'XLOG 1.4.2, XLOG 4') :-
catch(offset(_,_), error(E,_), true),
E == instantiation_error.
/* call_nth(G, N) */
runner_pred(call_nth,2, calculate, sequence, 'XLOG 1.4.3').
runner_case(call_nth,2, calculate, sequence, 'XLOG 1.4.3, XLOG 1') :-
findall(N, call_nth(between(5, 10, _), N), L),
L == [1,2,3,4,5,6].
runner_case(call_nth,2, calculate, sequence, 'XLOG 1.4.3, XLOG 2') :-
call_nth(between(5, 10, X), 3),
X == 7.
runner_case(call_nth,2, calculate, sequence, 'XLOG 1.4.3, XLOG 3') :-
\+ call_nth(repeat, 0).
runner_case(call_nth,2, calculate, sequence, 'XLOG 1.4.3, XLOG 4') :-
catch(call_nth(_,_), error(E,_), true),
E == instantiation_error.
/* distinct(G) */
d(f(A,A)).
d(f(a,a)).
d(f(B,B)).
runner_pred(distinct,1, calculate, sequence, 'XLOG 1.4.4').
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 1') :-
L = [A,_,A], findall(X, distinct(member(X, L)), R),
R = [C,D], C \== D.
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 2') :-
L = [1-b,2-a,1-a,2-a], findall(X-Y, distinct(member(X-Y, L)), R),
R == [1-b, 2-a, 1-a].
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 3') :-
\+ distinct(fail).
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 4') :-
distinct(repeat), !.
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 5') :-
findall(X, distinct(d(X)), L),
L = [f(A, B), f(a, a)], var(A), var(B).
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 6') :-
findall(X, distinct(d(X)), L),
L = [f(A, B), f(a, a)], A == B.
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 7') :-
findall(X,distinct((distinct(X=1);distinct(X=1))), L),
L == [1].
runner_case(distinct,1, calculate, sequence, 'XLOG 1.4.4, XLOG 8') :-
catch(distinct(_), error(E,_), true),
E == instantiation_error.
/* firstof(T, Q) */
runner_pred(firstof,2, calculate, sequence, 'XLOG 1.4.5').
runner_case(firstof,2, calculate, sequence, 'XLOG 1.4.5, XLOG 1') :-
findall(Y-X, firstof(X, ((Y=2;Y=1;Y=2), between(1,3,X))), R),
R == [2-1, 1-1].
runner_case(firstof,2, calculate, sequence, 'XLOG 1.4.5, XLOG 2') :-
findall(Y-X, firstof(X, ((Y=A;Y=_;Y=A), between(1,3,X))), R),
R = [C-1, D-1], C \== D.
runner_case(firstof,2, calculate, sequence, 'XLOG 1.4.5, XLOG 3') :-
catch(firstof(_,1), error(E,_), true),
E == type_error(callable, 1).