use main to call all tests:
This commit is contained in:
parent
adf3ed0311
commit
e4bcc5e8a2
@ -19,9 +19,23 @@
|
|||||||
:- use_module(library(gecode/clpfd)).
|
:- use_module(library(gecode/clpfd)).
|
||||||
:- use_module(library(maplist)).
|
:- use_module(library(maplist)).
|
||||||
|
|
||||||
|
main :- ex(Ex, People, Names, _Preferences),
|
||||||
|
photo(Ex, People, Amount ),
|
||||||
|
format( 'Example ~a: ~w~n', [Ex, Amount]),
|
||||||
|
maplist(join, People, Names, PeopleNames),
|
||||||
|
keysort( PeopleNames, SortedPeopleNames),
|
||||||
|
maplist(join, _People, SortedNames, SortedPeopleNames),
|
||||||
|
maplist(output, SortedNames ),
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
|
join( Key, El, Key-El ).
|
||||||
|
|
||||||
|
output( Name ) :- format(' ~a~n', [Name]).
|
||||||
|
|
||||||
% 5 people want to have a photograph together, but they have preferences.
|
% 5 people want to have a photograph together, but they have preferences.
|
||||||
photo(Ex, People, Amount) :-
|
photo(Ex, People, Amount) :-
|
||||||
ex(Ex, People, Preferences),
|
ex(Ex, People, _, Preferences),
|
||||||
length(People, Len),
|
length(People, Len),
|
||||||
Len0 is Len-1,
|
Len0 is Len-1,
|
||||||
People ins 0..Len0,
|
People ins 0..Len0,
|
||||||
@ -39,7 +53,9 @@ photo(Ex, People, Amount) :-
|
|||||||
preference_satisfied(X-Y, B) :-
|
preference_satisfied(X-Y, B) :-
|
||||||
abs(X - Y) #= 1 #<==> B.
|
abs(X - Y) #= 1 #<==> B.
|
||||||
|
|
||||||
ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
|
ex(s,[Alice,Bob,Carl,Deb,Evan],
|
||||||
|
['Alice','Bob','Carl','Deb','Evan'],
|
||||||
|
[Alice-Carl,
|
||||||
Carl-Deb,
|
Carl-Deb,
|
||||||
Deb-Alice,
|
Deb-Alice,
|
||||||
Evan-Alice,
|
Evan-Alice,
|
||||||
@ -49,6 +65,7 @@ ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
|
|||||||
Evan-Bob]).
|
Evan-Bob]).
|
||||||
|
|
||||||
ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
|
ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
|
||||||
|
['Betty','Chris','Donald','Fred','Gary','Mary','Paul','Peter','Susan'],
|
||||||
[Betty-Donald,
|
[Betty-Donald,
|
||||||
Betty-Gary,
|
Betty-Gary,
|
||||||
Betty-Peter,
|
Betty-Peter,
|
||||||
|
@ -2,6 +2,18 @@
|
|||||||
:- use_module(library(gecode/clpfd)).
|
:- use_module(library(gecode/clpfd)).
|
||||||
:- use_module(library(maplist)).
|
:- use_module(library(maplist)).
|
||||||
|
|
||||||
|
main :-
|
||||||
|
between(1,10,N),
|
||||||
|
I is N*100,
|
||||||
|
statistics( runtime, _ ),
|
||||||
|
once( queens(I, _Queens) ),
|
||||||
|
statistics( runtime, [DT|_] ),
|
||||||
|
% findall(Queens, queens(I, Queens), Solutions ),
|
||||||
|
% length( Solutions, N),
|
||||||
|
format('~d took ~w msec to find first solution.~n', [I, DT]),
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
queens(N, Queens) :-
|
queens(N, Queens) :-
|
||||||
length(Queens, N),
|
length(Queens, N),
|
||||||
Queens ins 1..N,
|
Queens ins 1..N,
|
||||||
@ -35,4 +47,3 @@ constrain(Q, I, R, J, J1) :-
|
|||||||
J1 is J+1,
|
J1 is J+1,
|
||||||
Q + I #\= R + J,
|
Q + I #\= R + J,
|
||||||
Q - I #\= R - J.
|
Q - I #\= R - J.
|
||||||
|
|
||||||
|
@ -18,6 +18,16 @@
|
|||||||
|
|
||||||
:- use_module(library(gecode/clpfd)).
|
:- use_module(library(gecode/clpfd)).
|
||||||
|
|
||||||
|
main :-
|
||||||
|
statistics( runtime, _ ),
|
||||||
|
once( send_more_money(Letters) ),
|
||||||
|
statistics( runtime, [DT|_] ),
|
||||||
|
% findall(Queens, queens(I, Queens), Solutions ),
|
||||||
|
% length( Solutions, N),
|
||||||
|
format('took ~w msec to find first solution, ~w.~n', [I, DT, Letters]),
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
% S E N D
|
% S E N D
|
||||||
% + M O R E
|
% + M O R E
|
||||||
% ---------
|
% ---------
|
||||||
|
@ -18,8 +18,19 @@
|
|||||||
|
|
||||||
:- use_module(library(gecode/clpfd)).
|
:- use_module(library(gecode/clpfd)).
|
||||||
|
|
||||||
|
|
||||||
|
main :-
|
||||||
|
statistics( runtime, _ ),
|
||||||
|
once( send_most_money(Letters, Money) ),
|
||||||
|
statistics( runtime, [DT|_] ),
|
||||||
|
% findall(Queens, queens(I, Queens), Solutions ),
|
||||||
|
% length( Solutions, N),
|
||||||
|
format('took ~w msec to find first solution, ~w.~n', [DT, Letters:Money]),
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
% S E N D
|
% S E N D
|
||||||
% + M O S T
|
% + M O S T
|
||||||
% ---------
|
% ---------
|
||||||
% M O N E Y
|
% M O N E Y
|
||||||
send_most_money(Letters, Money) :-
|
send_most_money(Letters, Money) :-
|
||||||
|
@ -5,8 +5,12 @@
|
|||||||
:- use_module(library(gecode/clpfd)).
|
:- use_module(library(gecode/clpfd)).
|
||||||
:- use_module(library(maplist)).
|
:- use_module(library(maplist)).
|
||||||
|
|
||||||
|
main :-
|
||||||
|
sudoku(Ex, Els),
|
||||||
|
fail.
|
||||||
|
main.
|
||||||
|
|
||||||
sudoku( Ex ) :-
|
sudoku( Ex, Els ) :-
|
||||||
problem(Ex, Els),
|
problem(Ex, Els),
|
||||||
output(Els).
|
output(Els).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user