так пытается сделать бинарный алгоритм поиска в прологеПролог Binary Алгоритм поиска
%checks to see if a value is contained in a list of integers,
%using binary search tactics
%success base case
%A list contains a value if its center is the value
contains(List, Value):- even_division(_, [Value|_], List).
%case that Value is large
%A list contains a value if the value is larger than the center,
%and the second half of the list contains the value
contains(List, Value):- even_division(_, [Center|SecondHalf], List),
Center<Value, SecondHalf \= [],
contains(SecondHalf, Value).
%case that Value is small
%A list contains a value if the value is smaller than the center,
%and the first half of the list contains the value
contains(List, Value):- even_division(FirstHalf, [Center|_], List),
Center>Value, FirstHalf\=[],
contains(FirstHalf, Value).
%even_division(First, Second, Xs) is true when
% Xs is the concatenation of First and Second,
% and First and Second are either the same length
% or Second is one element longer than first.
even_division(First, Second, Xs) :- append(First, Second, Xs),
length(First,F), length(Second,S),
S>=F, S-F=<1.
однако, что я хочу сделать, это вместо того, чтобы печатать из списка я хочу создать его базу по ряду пунктов я хочу это так сказать, я хочу сделать двоичный поиск в списке из 5000 элементов, очевидно, я не могу напечатать 5000 предметов в нем, так как я могу его создать?
поэтому я понял, что могу создать список вроде этого '% range (I, K, L): - I <= K, а L - список, содержащий все % последовательных целых чисел от I до K. % (целое число, целое число, список) (+, +,?) диапазон (I, I, [I]). диапазон (I, K, [I | L]): - I
russiandobby