about summary refs log tree commit diff
path: root/others/volume1/clib.pas
diff options
context:
space:
mode:
Diffstat (limited to 'others/volume1/clib.pas')
-rw-r--r--others/volume1/clib.pas32
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.