Files
mercury/tests/debugger/queens.m
Zoltan Somogyi ed1716bf35 Clean up the debugger tests directory by (a) removing the long obsolete
Estimated hours taken: 1

Clean up the debugger tests directory by (a) removing the long obsolete
*_lib files, and (b) separating out the three roles of the queens.m
into mdb_command_test.m and interactive.m as well as queens.m.

tests/debugger/mdb_command_test.m:
	Add a trivial source file for this test. The other files of the test
	case (.inp, .exp) already existed.

tests/debugger/queens.{m,exp,inp}:
	Remove the tests of interactive functionality.

tests/debugger/interactive.{m,exp,inp}:
	A renamed copy of the old queens.m, with the interactive functionality
	intact. Note: since this test case is currently disabled, I cannot
	be sure that the .exp file is quite correct in every detail.

tests/debugger/*_lib.*:
	Removed these obsolete test cases, since for a while now we have
	avoided depending on whether the library was compiled with tracing
	or not by leaving all library code to the end and not printing
	or stopping at any event inside library code.

tests/debugger/Mmakefile:
	Make the necessary updates to accommodate the above changes.
1999-04-16 01:13:04 +00:00

102 lines
1.6 KiB
Mathematica

:- module queens.
:- interface.
:- import_module io.
:- pred main(io__state, io__state).
:- mode main(di, uo) is cc_multi.
:- implementation.
:- import_module list, int.
main -->
( { data(Data), queen(Data, Out) } ->
print_list(Out)
;
io__write_string("No solution\n")
).
:- pred data(list(int)).
:- mode data(out) is det.
:- pred queen(list(int), list(int)).
:- mode queen(in, out) is nondet.
:- pred qperm(list(T), list(T)).
:- mode qperm(in, out) is nondet.
:- pred qdelete(T, list(T), list(T)).
:- mode qdelete(out, in, out) is nondet.
:- pred safe(list(int)).
:- mode safe(in) is semidet.
:- pred nodiag(int, int, list(int)).
:- mode nodiag(in, in, in) is semidet.
data([1,2,3,4,5]).
queen(Data, Out) :-
qperm(Data, Out),
safe(Out).
qperm([], []).
qperm([X|Y], K) :-
qdelete(U, [X|Y], Z),
K = [U|V],
qperm(Z, V).
qdelete(A, [A|L], L).
qdelete(X, [A|Z], [A|R]) :-
qdelete(X, Z, R).
safe([]).
safe([N|L]) :-
nodiag(N, 1, L),
safe(L).
nodiag(_, _, []).
nodiag(B, D, [N|L]) :-
NmB is N - B,
BmN is B - N,
( D = NmB ->
fail
; D = BmN ->
fail
;
true
),
D1 is D + 1,
nodiag(B, D1, L).
:- pred print_list(list(int), io__state, io__state).
:- mode print_list(in, di, uo) is det.
print_list(Xs) -->
(
{ Xs = [] }
->
io__write_string("[]\n")
;
io__write_string("["),
print_list_2(Xs),
io__write_string("]\n")
).
:- pred print_list_2(list(int), io__state, io__state).
:- mode print_list_2(in, di, uo) is det.
print_list_2([]) --> [].
print_list_2([X|Xs]) -->
io__write_int(X),
(
{ Xs = [] }
->
[]
;
io__write_string(", "),
print_list_2(Xs)
).