Keep It Simple, Stupid | |
PerlMonks |
Re: (Golf) Dependency List Prioritizationby petral (Curate) |
on Mar 18, 2002 at 15:14 UTC ( [id://152487]=note: print w/replies, xml ) | Need Help?? |
This seems to do it at 93 (but there should be ways to shorten it):
that's: 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: 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
In Section
Meditations
|
|