in reply to Re: Triangle Golf
in thread Triangle Golf
Here's some variations on MeowChow's idea above:
a perfectly respactable program, about 140 chars (after the #!.../):
a perfectly respactable program, about 140 chars (after the #!.../):
> triangle.pl a.txt w.txt#!/usr/local/bin/perl -ln0777 $\ =' '; $c = 0; s/^\s+//; s/\s+/ /gs; while ( s/(.{$c,}?. |.+$)// ) { print " " x (40 - ($c = 1 + length $1) / 2), $1 }
a one-liner, 74 chars (+6 extra flag chars):a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a The same principle applies to any text file, basically splitting words only on spaces or new lines
and pretty well golfed, 66 chars (+6 extra flag chars):> perl -ln0777we '$c=0;s/\s+/ /sg;print" "x(40-($c=length$1)/2),$1 whi +le s/(.{$c,}?. |.+$)//' a.txt w.txt a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a The same principle applies to any text file, basically splitting words only on spaces or new lines
p> perl -ln0777e's/\s+/ /sg;print$"x(40-($c=length$&)/2),$&while s/.{0$ +c,}?. |.+$//' a.txt w.txt a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a The same principle applies to any text file, basically splitting words only on spaces or new lines > perl -ln0777e's/\s+/ /sg;print$"x(40-($c=length$&)/2),$&while s/.{0$ +c,}?. |.+$//' w.txt a.txt The same principle applies to any text file, basically splitting words only on spaces or new lines a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Triangle Golf
by MeowChow (Vicar) on Apr 25, 2001 at 22:10 UTC | |
by petral (Curate) on Apr 26, 2001 at 21:27 UTC |
In Section
Cool Uses for Perl