[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Shell Golf
I suppose my best without warnings, and with spaces is:
perl -pe'$_=length()." $ARGV $_"' *.pl|sort -n|tail -1
weighing in at 54
in ugly format (w/o spaces), and with a warning:
perl -pe'$_=length.$ARGV.$_' *.pl|sort -n|tail -1
weighin in at 49
(note that the only diff from my last ones is one space that wasn't
needed was removed, and I actually counted correctly :)
Jamon
-----Original Message-----
From: silug-discuss-owner@silug.org
[mailto:silug-discuss-owner@silug.org] On Behalf Of Steven Pritchard
Sent: Thursday, May 08, 2003 12:59 AM
To: luci-discuss@luci.org
Cc: silug-discuss@silug.org
Subject: Re: Shell Golf
On Wed, May 07, 2003 at 06:46:41PM +0000, mike808@users.sourceforge.net
wrote:
> My solution clocks in at a hefty *59* characters. Any contenders?
>
> perl -p -e '$_=length($_)." $ARGV $_"' *.pl|sort -n|tail -1
Not as short, but a heck of a lot more efficient:
perl -e 'while(<>){$x=length$_;@n=($x,$ARGV,$_)if$x>$n[0]}print"@n"'
*.pl
1000 runs of the original:
8.25user 7.59system 0:16.40elapsed 96%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (567238major+175905minor)pagefaults 0swaps
1000 runs of my script:
5.24user 3.53system 0:09.61elapsed 91%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (316240major+71180minor)pagefaults 0swaps
This is in a directory with 9 .pl files with a total of 355 lines, so
the difference is *much* larger with more/bigger files. Here's a
directory with 9 .c files with a total of 3868 lines:
Original:
38.51user 11.17system 0:52.86elapsed 93%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (567238major+234930minor)pagefaults 0swaps
Mine:
9.26user 3.87system 0:16.95elapsed 77%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (316240major+71195minor)pagefaults 0swaps
And to get really crazy, I tried the same thing *once* on an old-ish
copy of XFree86 that I happened to have lying around (only on *.h
though, otherwise the argument list was too long ;):
Original:
9.67user 1.78system 0:12.29elapsed 93%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (908major+9030minor)pagefaults 0swaps
Mine:
1.11user 0.24system 0:01.51elapsed 89%CPU (0avgtext+0avgdata
0maxresident)k
0inputs+0outputs (655major+436minor)pagefaults 0swaps
That's on 569644 lines in 2294 files.
Steve
--
steve@silug.org | Southern Illinois Linux Users Group
(618)398-7360 | See web site for meeting details.
Steven Pritchard | http://www.silug.org/
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.
-
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.