Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re (tilly): (tye)Re: Golf: Tree searching

by tilly (Archbishop)
on Apr 20, 2001 at 02:22 UTC ( #74019=note: print w/replies, xml ) Need Help??

in reply to (tye)Re: Golf: Tree searching
in thread Golf: Tree searching

Very nice. I tried several times without success to come up with a good non-recursive solution. The above not only is short, but it really does the binary search, and applying standard golfing techniques, it comes up a winner at 55:
sub f{ ($s,$t)=@_;$t=$$t{$$t{d}gt$s?l:r}while$t&&$$t{d}ne$s;$t }
(Or 57 if you add my to kill side effects. Still better than anything I thought of.)

Note that this is much less readable than what tye wrote, but every transformation is fairly mechanical compression of the code...

Replies are listed 'Best First'.
(tye)Re2: Golf: Tree searching
by tye (Sage) on Apr 20, 2001 at 09:44 UTC

    Thanks, but credit goes to Masem for the algorithm as mine was just mechanical compression of Masem's original code. (:

            - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://74019]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-05-26 11:02 GMT
Find Nodes?
    Voting Booth?