diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-02-21 21:09:39 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-02-21 21:09:39 +0700 |
commit | 7d19f480637e9e880b98dabfbcf8e885b0a2d3b9 (patch) | |
tree | fa52914a2e58bc13570839fa297be05b7b7616bf /others/volume1/clib.pas | |
parent | f2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa (diff) | |
download | cp-7d19f480637e9e880b98dabfbcf8e885b0a2d3b9.tar.gz |
Update others/volume1
Diffstat (limited to 'others/volume1/clib.pas')
-rw-r--r-- | others/volume1/clib.pas | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/others/volume1/clib.pas b/others/volume1/clib.pas index 101bad3..b9037cd 100644 --- a/others/volume1/clib.pas +++ b/others/volume1/clib.pas @@ -125,16 +125,21 @@ interface 12200160415121876738 ); - procedure qsort(var a : intar); function gcd(x, y: int64): int64; function isprime(x: int64): boolean; function issquare(x: int64): boolean; function ispalindrome(s: ansistring): boolean; function all(b: array of boolean): boolean; + + procedure qsort(var a : intar); function bsearch( a: intar; x: int64 ): int64; + function bisect_left( + a: intar; + x: int64 + ): int64; implementation @@ -176,6 +181,7 @@ implementation end; + (* Translated from Python 3 math module *) function gcd(x, y: int64): int64; var z: int64; begin @@ -254,4 +260,28 @@ implementation bsearch := -1 end; + + (* Translated from Python 3 bisect module *) + function bisect_left( + a: intar; + x: int64 + ): int64; + + var + l, h, m: int64; + + begin + l := 0; + h := length(a); + while l < h do + begin + m := (l + h) div 2; + if a[m] < x then + l := m + 1 + else + h := m + end; + bisect_left := l + end; + end. |