Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^5: du -h, sorted

by hbm (Hermit)
on Feb 26, 2009 at 16:28 UTC ( #746588=note: print w/ replies, xml ) Need Help??

in reply to Re^4: du -h, sorted
in thread du -h, sorted

Slick! But how about 70, using 'x' instead of '**', and 'die' instead of 'print':

perl -e'sub c{pop=~/.\s/;(ord$&&7)x7+$`}die sort{c($b)<=>c$a}`du -h`'

Comment on Re^5: du -h, sorted
Download Code
Replies are listed 'Best First'.
Re^6: du -h, sorted
by bellaire (Hermit) on Feb 26, 2009 at 19:30 UTC
    Very impressive. Made me waste a lot of time trying to beat it!

    I think I've got it just a little shorter. I don't know if the time I spent on this has brought me any closer to enlightenment, but it did make me fast (as in skip a meal)...
    perl -e'%h=map{/.\s/;7**(ord$&&30)-$`,$_}`du -h`;die @h{sort %h}'
    66 characters.

    The key is the 7 to the power of ord(char) bitwise 30 part. I had to write a little perl script that would find the magic values 7 and 30 which would work for a lexicographic (default) sort. That is, I take 7 to the power of those values, and subtract the value of $` ... to produce hash keys which sort properly.

    Then I take a hash slice on the sorted result. The sort actually returns the entire flattened hash sorted, keys and values, but since the values in that hash don't map to anything, they are silent.

    I think I need to go get something to eat.

      Beautiful!! And I hear you about the food thing. (Where are you? We could see how small a lunch we could get.)

      But I'm afraid you threw me a softball, easily shorted to 64:

      perl -e'%h=map{/.\s/;7**(ord$&&30)-$`,$_}`du -h`;die@h{sort%h}'
        I guess fasting doesn't necessarily improve golfing ability. :)

        Well played! I don't think I'll be able to get it any shorter than that.

        Oh, faux pas! Surely you are more honorable than that!

        And you didn't even know bears could type.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-11-25 20:35 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (690 votes), past polls