From 7d19f480637e9e880b98dabfbcf8e885b0a2d3b9 Mon Sep 17 00:00:00 2001 From: Raphael McSinyx Date: Tue, 21 Feb 2017 21:09:39 +0700 Subject: Update others/volume1 --- others/volume1/clib.pas | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'others/volume1/clib.pas') 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. -- cgit 1.4.1