Oct 4, 2015 17:19
I mean, there are several tricks along the way.
Oct 4, 2015 17:19
@Ixrec hi, remember I've been asking about binary search. I finally got the idea. I.e. converted 3 predicates solution to a single predicate solution. Also I have a sort of step by step conversion instruction. Planning to make a page on github on it.
Sep 23, 2015 06:38
and I just was a bit distracted and lost a thread
Sep 23, 2015 06:14
I was just looking at binary search again today
Sep 23, 2015 06:12
hi
Sep 22, 2015 07:31
got to go to work now
Sep 22, 2015 07:30
Thanks a lot, you've been really helpful
Sep 22, 2015 07:30
well, I still don't get it, but thanks for the clue, I'll look at it
Sep 22, 2015 07:29
oh, you mean lo = mid +1/hi = mid - 1
Sep 22, 2015 07:28
what do you mean by +1/-1 symmetry?
Sep 22, 2015 07:27
it works, cool
Sep 22, 2015 07:27
let's add + 1
Sep 22, 2015 07:27
I mean, Imagine I was the guy who devised an algorithm, it's like, wow, my algorithm doesn't work
Sep 22, 2015 07:26
ye, I just don't get it
Sep 22, 2015 07:21
Thanks a lot for your help Ixrec, I'll check it when I have free time. thx bye
Sep 22, 2015 07:20
The code will get stuck in a loop. It will always select the first element as mid, but then will not move the lower bound because it wants to keep the no in its search space. The solution is to change mid = lo + (hi-lo)/2 to mid = lo + (hi-lo+1)/2, i.e. so that it rounds up instead of down.
Sep 22, 2015 07:20
i.e. this one
Sep 22, 2015 07:19
also that + 1 bit breaks my mind
Sep 22, 2015 07:19
I guess I just need to take it and slowly transform to a second one
Sep 22, 2015 07:19
the only solution I can clearly reason about, is the first one
Sep 22, 2015 07:18
it kinda works, but I don't understand why
Sep 22, 2015 07:18
but I don't understand it
Sep 22, 2015 07:18
look, I mean I can write that binary search even in predicate version
Sep 22, 2015 07:04
and pass just predicate and domain
Sep 22, 2015 07:04
or even probably combine function with predicate
Sep 22, 2015 07:03
you can also pass a predicate instead of target
Sep 22, 2015 07:03
and a function domain
Sep 22, 2015 07:03
so in this algorithm you described, you basically pass in it a function
Sep 22, 2015 07:01
Ixrec, yes, that's the algorithm I had in mind.
Sep 22, 2015 06:56
yes, I'm talking about taking first algorithm and replacing element addressing with a function call
Sep 22, 2015 06:55
That's just it
Sep 22, 2015 06:54
Ixrec , I'm talking about replacing element addressing with a function call, because one of the arguments I heard for the second solution was that you can use it not with an array, but just with a function. So my counterpoint is that you can also use first solution with a function as element addressing is basically a function too.
Sep 22, 2015 06:51
I have two points in defence of the first soltuion: 1) you don't need to provide a complete search space (i.e. filled A array), as you can easily replace element addressing with a function call. 2) it's easier to reason about.
Sep 22, 2015 06:47
what it actually does inside it
Sep 22, 2015 06:47
the problem with that solution is that it's hard to reason about
Sep 22, 2015 06:46
I"m saying that you can use a function instead of addressing element in an array
Sep 22, 2015 06:43
you can replace A[mid] with function
Sep 22, 2015 06:41
the second algorithm is binary_search(lo, hi, p)
Sep 22, 2015 06:40
and it doesn't help that second algorithm is pretty hard to reason about
Sep 22, 2015 06:40
that's why I'm confused
Sep 22, 2015 06:40
because I'm trying to understand all the quirky bits in the second algorithm
Sep 22, 2015 06:39
I'm confused
Sep 22, 2015 06:38
lol
Sep 22, 2015 06:34
you devised
Sep 22, 2015 06:34
you can interchange operator for a method call
Sep 22, 2015 06:28
@Brandin 1) algorithm is not the same. 2) you can replace A[mid] with a function call, so you don't actually need an array as a parameter 3) you can replace '==' and '<' operators with your own type 'methods' 4) as for the boundaries, probably there is a way to implement this functionality with the first approach too.
Sep 22, 2015 05:45
se
Sep 22, 2015 05:45
doesn't make sene
Sep 22, 2015 05:45
but the second one