Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
23
Task/Binary-search/Prolog/binary-search.pro
Normal file
23
Task/Binary-search/Prolog/binary-search.pro
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
bin_search(Elt,List,Result):-
|
||||
length(List,N), bin_search_inner(Elt,List,1,N,Result).
|
||||
|
||||
bin_search_inner(Elt,List,J,J,J):-
|
||||
nth(J,List,Elt).
|
||||
bin_search_inner(Elt,List,Begin,End,Mid):-
|
||||
Begin < End,
|
||||
Mid is (Begin+End) div 2,
|
||||
nth(Mid,List,Elt).
|
||||
bin_search_inner(Elt,List,Begin,End,Result):-
|
||||
Begin < End,
|
||||
Mid is (Begin+End) div 2,
|
||||
nth(Mid,List,MidElt),
|
||||
MidElt < Elt,
|
||||
NewBegin is Mid+1,
|
||||
bin_search_inner(Elt,List,NewBegin,End,Result).
|
||||
bin_search_inner(Elt,List,Begin,End,Result):-
|
||||
Begin < End,
|
||||
Mid is (Begin+End) div 2,
|
||||
nth(Mid,List,MidElt),
|
||||
MidElt > Elt,
|
||||
NewEnd is Mid-1,
|
||||
bin_search_inner(Elt,List,Begin,NewEnd,Result).
|
||||
Loading…
Add table
Add a link
Reference in a new issue