I hereby claim:
- I am rjperrella on github.
- I am rperrella (https://keybase.io/rperrella) on keybase.
- I have a public key ASAqAZyXvpcf5fXJ3m8YEfnucxPHcAiV_x_6VMT_s-0tVwo
To claim this, I am signing this object:
#!/usr/bin/perl | |
use Test::Simple tests=>4; | |
sub bsearch { | |
my ($aref, $item, $lo, $hi) = @_; | |
return -1 if $lo > $hi; | |
my $mid = ($hi + $lo) >> 1; | |
return $mid if ($aref->[$mid] == $item); | |
if ($item > $aref->[$mid]) { | |
@_ = ($aref, $item, $mid+1, $hi); |
# Not efficient - this is better done as a while loop (unless Python can optimize tail-recursion...) | |
# return index of item. | |
# assumes arry is in ascending order. | |
# return -1 if item is not found in the array. | |
# interestingly, the bug I had where line 10 had high - low/ 2 still gave correct answers because the array was so small (and | |
# perhaps also it was the dimensions? | |
def bsearch(arry, low, high, item): | |
if low > high: | |
return -1 # not found |
I hereby claim:
To claim this, I am signing this object: