This seems to do it at 93 (but there should be ways to shorten it):
sub f {
$h{$_}||=[]for map@$_,%h=@_;sub x{my$x=1;$x+=x($_)for@{@h{@_}||[]};$x}
+sort{x($a)<=>x$b}keys%h
}
that's:
sub f {
$h{$_}||=[]for map@$_,%h=@_;
sub x {
my$x=1;
$x+=x($_)for@{@h{@_}||[]};
$x
}
sort{x($a)<=>x$b}keys%h
}
I think this algorithm is in the panther book[1].   The basic idea is that if you count the dependencies all the way down, then something which depends on something else must have a count of at least 1 more than its depender(?).   Neither the exact counts, nor exactly what's being counted matter (that is 'a' can count 'd' in both 'b' and 'c').
[1]
(update) Well, something like it.   I don't want to blame the authors for my crude implementation.
one more
update:  
@h{@$_}=@h{@$_}for%h=@_;and
$x+=x($_)for@{@h{@_}||0};lowers it to 88.
well, one more
update:   Actually, there's no need to add all those 1's, just let the size of the list be the value:
sub x {
1,map{x($_)}@{@h{@_}||0}
}
which makes the whole thing 78:
@h{@$_}=@h{@$_}for%h=@_;sub x{1,map{x($_)}@{@h{@_}||0}}sort{x($a)<=>x$b}keys%h   
p
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.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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?
See Writeup Formatting Tips and other pages linked from there for more info.