Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: (Golf) Shortest Graph Distance

by no_slogan (Deacon)
on May 12, 2001 at 00:03 UTC ( #79830=note: print w/replies, xml ) Need Help??


in reply to (Golf) Shortest Graph Distance

My first try. Passes -w and strict. 172 characters.
sub path { my($g,$a,$b,$x,$y,%s)=@_;$s{$a}=[0,[$a]];for(%$g){for(keys%s){$s{$x}&& +$s{$_}[0]+$y>$s{$x}[0]or$s{$x}=[$s{$_}[0]+$y,[@{$s{$_}[1]},$x]]while( +$x,$y)=each%{$g->{$_}}}}$s{$b}[1] }

Update:Oops, it returns an arrayref instead of an array. No point in fixing it, chipmunk's solution puts mine to shame anyway.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2023-12-04 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (20 votes). Check out past polls.

    Notices?