Re: outputting fun
by indigo (Scribe) on Aug 29, 2000 at 20:08 UTC
|
#!/usr/bin/perl -w
use strict;
my $string = 'ABCDEFGFEDCBA';
print "$string\n" and $string =~ s/$_/ /g for reverse 'A' .. 'G';
| [reply] [Watch: Dir/Any] [d/l] |
RE: outputting fun
by Shendal (Hermit) on Aug 29, 2000 at 19:51 UTC
|
#!/usr/bin/perl -w
use strict; # always
$_ = join("",('A' .. 'G'), reverse('A' .. 'F'),"\n");
foreach my $letter (reverse ('A' .. 'G')) { print; s/$letter/ /g; }
Cheers,
Shendal
| [reply] [Watch: Dir/Any] [d/l] |
Re: outputting fun
by Corion (Patriarch) on Aug 29, 2000 at 19:47 UTC
|
Here's my try at it. It uses two forms of string replacement - one transliteration, replacing every G with a space, and one regular expression, replacing a single character, followed by one or more spaces and then that character again, with two more spaces.
#!/usr/bin/perl -w
use strict;
my $line;
print( $line = join( "", ('A' .. 'G'), reverse ( 'A'..'F' )), "\n" );
$line =~ tr/G/ /;
print( $line, "\n" );
while ($line !~ /^\s+$/) {
$line =~ s/(\S)(\s+)\1/ $2 /;
print( $line, "\n");
};
This is obviously not the smallest possible code, but a bit more Perlish and elegant (IMholyO) :-)
| [reply] [Watch: Dir/Any] [d/l] |
|
Just would like to say that Iam a wingnut :)
for(my($c)=71,my($i)=0; $c >= 65; $c--,$i++) {
print (
(chr(65)..chr($c)),
(' 'x($i+($i-1))),
reverse(chr(65)..chr(($c==71)? $c-1 : $c)),
"\n"
);
}
p.s. I broke it into multi-line so that it was readable :)
lindex
/****************************/
jason@gost.net, wh@ckz.org
http://jason.gost.net
/*****************************/
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
print <<EOF;
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
EOF
How about?
$a = "ABCDEFGFEDCBA\n";
print($a), substr($a, 7-$_, 2*$_-1) = " " ." " x ($_-1) for 1..7
-- stef | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: outputting fun
by Boogman (Scribe) on Aug 29, 2000 at 19:51 UTC
|
Here's another way. I just printed the first line cause it didn't really fit the pattern used for the rest of the lines...
print 'ABCDEFGFEDCBA', "\n";
my @letters = ( 'A' .. 'F' );
for ( 0 .. $#letters ) {
print @letters[ 0 .. $#letters - $_ ], ' ' x ( 1 + 2 * $_ ),
reverse( @letters[ 0 .. $#letters - $_ ] ), "\n";
}
A bit shorter, but I must say I like Corion's solution better. | [reply] [Watch: Dir/Any] [d/l] |
Re: outputting fun
by tye (Sage) on Aug 29, 2000 at 20:43 UTC
|
#!/usr/bin/perl -l
print reverse join"\n",reverse map{reverse sprintf
"%-6.6s%7s",(reverse join"",@$_=reverse@$_),reverse join
"",reverse@$_}reverse map{[reverse'A'..$_]}reverse'A'..'G'
I think I can eliminate one of those reverses, but I'm not sure which one. (:
-
tye
(but my friends call me "Tye") | [reply] [Watch: Dir/Any] [d/l] [select] |
|
how about eliminating 8 of them:
#!/usr/bin/perl -l
print join $/, map { sprintf "%-6.6s%7s", join("", @$_),
join("", reverse @$_) } map { [ 'A' .. $_ ] } reverse 'A'..'G';
| [reply] [Watch: Dir/Any] [d/l] |
Re: outputting fun
by cwest (Friar) on Aug 29, 2000 at 22:51 UTC
|
BEGIN{$_=7 # Change this number to control pivot
-1}foreach $.(int(length()/2)..length()-2){print
((/\s/?s/\w(\s+)\w/ $1 /:s/(\w{$;})./$1 /)?$_:1)
;}BEGIN{($;,$_,$\)=($_,join(''=>chr(65)..chr(65+
$_),reverse(chr(65)..chr(65+$_-1))),$/);print}
because I'm nuts, that's why :-)
--
Casey
| [reply] [Watch: Dir/Any] [d/l] |
Re (tilly) 1: outputting fun
by tilly (Archbishop) on Mar 28, 2001 at 05:17 UTC
|
$_="ABCDEFGFEDCBA\n";
print;
print while s/(?<!^)(G|\b\w|\w\b)(?!$)/ /g;
| [reply] [Watch: Dir/Any] [d/l] |
Re: outputting fun
by Arry (Initiate) on Jan 09, 2002 at 19:16 UTC
|
OK, I'm new to this, but thought I would have a go.
On my own I get:
$d="ABCDEFGFEDCBA";
for($i=71;$i>64;$i-=1)
{
print "$d\n";
$c=chr($i);
$d =~ s/$c/ /g;
}
With a little help, I then got:
$_="ABCDEFGFEDCBA\n";for $r(reverse(A..G)){print; s/$r/ /g}
Same theory, better solution. | [reply] [Watch: Dir/Any] |