26 lines
830 B
Plaintext
26 lines
830 B
Plaintext
:- module amb.
|
|
:- interface.
|
|
:- import_module io.
|
|
:- pred main(io::di, io::uo) is cc_multi.
|
|
:- implementation.
|
|
:- import_module list, string, char, int.
|
|
|
|
main(!IO) :-
|
|
( solution(S) -> io.write_string(S, !IO), io.nl(!IO)
|
|
; io.write_string("No solutions found :-(\n", !IO) ).
|
|
|
|
:- pred solution(string::out) is nondet.
|
|
solution(S) :-
|
|
member(A, ["the", "that", "a"]),
|
|
member(N, ["frog", "elephant", "thing"]),
|
|
member(V, ["walked", "treaded", "grows"]),
|
|
member(E, ["slowly", "quickly"]),
|
|
S = join_list(" ", [A, N, V, E]),
|
|
rule1(A, N), rule1(N, V), rule1(V, E).
|
|
|
|
:- pred rule1(string::in, string::in) is semidet.
|
|
rule1(A, B) :- last_char(A) = C, first_char(B, C, _).
|
|
|
|
:- func last_char(string::in) = (char::out) is semidet.
|
|
last_char(S) = C :- index(S, length(S) - 1, C).
|