Your skill will accomplishwhat the force of many cannot PerlMonks

### Comment on

 Need Help??
Here's a solution, which I'm fairly certain works as intended (but we saw where that got me last time ;)
```sub path {
(*g,\$f,\$t)=@_;@s=map[\$f,\$_,\$r{\$_}],keys%{*r=\$g{\$f}};
push@s,map[@p,\$_,\$d+\$r{\$_}],keys%{*r=\$g{\$n}}
while(@s=sort{\$b->[-1]<=>\$a->[-1]}@s),\$d=pop@{*p=pop@s},
(\$n=\$p[-1])ne\$t;@p
}
170 characters... Yikes! I'm sure someone can do better than that!

Update: Hey, I don't need to do that complicated initialization of @s!

```sub path {
(*g,\$f,\$t)=@_;@s=[\$f,0];
push@s,map[@p,\$_,\$d+\$r{\$_}],keys%{*r=\$g{\$n}}
while(@s=sort{\$b->[-1]<=>\$a->[-1]}@s),\$d=pop@{*p=pop@s},
(\$n=\$p[-1])ne\$t;@p
}
142 characters!

Update:

This solution will be very slow on the NYC to SF test case, because it gets stuck moving back and forth between Chicago, Cleveland, and Detroit for a while, because SF is so far away. However, it will find the solution eventually.

Of course, this could be fixed by preventing the code from moving back to a node that has already been visited, but we're optimizing for character count, not for speed of execution! ;)

In reply to Re: (Golf) Shortest Graph Distance by chipmunk
in thread (Golf) Shortest Graph Distance by Masem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
As of 2017-11-20 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (284 votes). Check out past polls.

Notices?