Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

(tye)Re: Golf: Tree searching

by tye (Cardinal)
on Apr 19, 2001 at 22:06 UTC ( #73914=note: print w/ replies, xml ) Need Help??


in reply to Golf: Tree searching

sub f{($s,$t)=@_;{return$t if!$t||$t->{d}eq$s;$t=$t->{$t->{d}gt$s?l:r} +;redo}}

...I think...

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


Comment on (tye)Re: Golf: Tree searching
Download Code
Re (tilly): (tye)Re: Golf: Tree searching
by tilly (Archbishop) on Apr 20, 2001 at 02:22 UTC
    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...

      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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://73914]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-08-30 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls