Если взять за основу код, приведённый по
ссылке.
:- use_module(library(error)).
:- use_module(library(clpfd)).
:- use_module(library(lists)).
solve :-
load_file('n.txt', Words),
member([A1, A2, A3, A4, A5], Words),
member([A2, A6, A7, A8, A9], Words),
member([A3, A7, A10, A11, A12], Words),
member([A4, A8, A11, A13, A14], Words),
member([A5, A9, A12, A14, A15], Words),
writef("%s\n", [[A1, A2, A3, A4, A5]]),
writef("%s\n", [[A2, A6, A7, A8, A9]]),
writef("%s\n", [[A3, A7, A10, A11, A12]]),
writef("%s\n", [[A4, A8, A11, A13, A14]]),
writef("%s\n", [[A5, A9, A12, A14, A15]]).
load_file(File, Words) :-
open(File, read, Stream, []),
call_cleanup(load_strings(Stream,Words), close(Stream)).
load_strings(Stream, Words) :-
read_line_to_codes(Stream, T0),
load_strings(T0, Stream, Words).
load_strings(end_of_file, _Stream, []) :- !.
load_strings([], _Stream, []) :- !.
load_strings(Line, Stream, [Line|Rest]) :-
read_line_to_codes(Stream, NextLine),
load_strings(NextLine, Stream, Rest).
Скомпилировать:
swipl -O -c words.pl
И запустить…
абака
бадан
адепт
капер
антре
Находится моментально!