Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Binary-search/Maxima/binary-search.maxima
Normal file
20
Task/Binary-search/Maxima/binary-search.maxima
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
find(L, n) := block([i: 1, j: length(L), k, p],
|
||||
if n < L[i] or n > L[j] then 0 else (
|
||||
while j - i > 0 do (
|
||||
k: quotient(i + j, 2),
|
||||
p: L[k],
|
||||
if n < p then j: k - 1 elseif n > p then i: k + 1 else i: j: k
|
||||
),
|
||||
if n = L[i] then i else 0
|
||||
)
|
||||
)$
|
||||
|
||||
".."(a, b) := if a < b then makelist(i, i, a, b) else makelist(i, i, a, b, -1)$
|
||||
infix("..")$
|
||||
|
||||
a: sublist(1 .. 1000, primep)$
|
||||
|
||||
find(a, 27);
|
||||
0
|
||||
find(a, 421);
|
||||
82
|
||||
Loading…
Add table
Add a link
Reference in a new issue