in reply to (Golf) Dependency List Prioritization
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').sub f { $h{$_}||=[]for map@$_,%h=@_; sub x { my$x=1; $x+=x($_)for@{@h{@_}||[]}; $x } sort{x($a)<=>x$b}keys%h }
which makes the whole thing 78: @h{@$_}=@h{@$_}for%h=@_;sub x{1,map{x($_)}@{@h{@_}||0}}sort{x($a)<=>x$b}keys%h    psub x { 1,map{x($_)}@{@h{@_}||0} }
|
|---|