From bad1a909c7541989e3f16ab1d8700da225320886 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Thu, 6 Oct 2022 15:36:16 -0700 Subject: [PATCH] Just for me... (That's how you look all clever, but it's a dick move removing the commentary like that.) --- bigjoyints/lil_divmod.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/bigjoyints/lil_divmod.py b/bigjoyints/lil_divmod.py index 7d9cc10..a09fc7c 100644 --- a/bigjoyints/lil_divmod.py +++ b/bigjoyints/lil_divmod.py @@ -22,27 +22,13 @@ def find_greatest(low, high, f): for which f(n) and not f(n+1) is True. The greatest n which makes f(n) True. ''' - assert low <= high - - # Maybe the high number is already the one? if f(high): return high - - # No such luck, let's pick a number between low and high pivot = (low + high) >> 1 - #print(low, pivot, high) - - # If there isn't any such number in between low and high, - # that means there's only two numbers it could be: low or high - # and we already know it isn't high from the test above - # so it must be low. - if low == pivot: - assert f(low) and not f(low + 1) - return low - - assert low < pivot < high return ( + low + if low == pivot else find_greatest(pivot, high - 1, f) if f(pivot) else find_greatest(low, pivot - 1, f)