Inspired by a mind-numbingly dull CS lecture (Introduction to OO programming, AKA Java 101) I came up with this little abuse of nested ternary operators.
#!/usr/bin/perl $/=length($"=int<STDIN>)+1; for$!(1..$") {print$_<$"+1-$!?" "x$/:$_<=$"?sprintf"%*d",$/,$"+1-$_:$_<=$"+$!-1?spr +intf"%*d",$/,abs$"-1-$_:$_==2*$"?"\n":""foreach(1..(2*$"));}
Mostly your garden variety alphabet soup obfuscation, but you gotta start somewhere right? I've considered adding code to print less whitespace with lower numbers when printing a high number of rows, but decided not as it would make the output less like a pyramid (which is the desired effect after all).
Any thoughts?

Replies are listed 'Best First'.
Re: A first attempt at obfuscation.
by wolfger (Deacon) on Feb 17, 2005 at 14:46 UTC

    Nice. I like the patterns that can be obtained by entering numbers greater than the width of the terminal. More entertaining than the typical JAPH obfu.


    --
    Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
    perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'
      You know, I never noticed that. And now that you mention it, yeah those patterns are kinda cool.
      And to be honest I never quite saw the appeal of the JAPH, except possibly as an exercise in restraint (cf. the French oulipo literary movement if you know it).
Re: A first attempt at obfuscation.
by jdalbec (Deacon) on Feb 21, 2005 at 13:56 UTC
    It's actually pretty readable once it's properly formatted (and once you've run it to see what it does). It runs fine with strict and warnings, too. I wasn't familiar with the use of "%*d" in sprintf.
    #! /usr/bin/perl use strict; use warnings; $/ = length( $" = int <STDIN> ) + 1; for $! ( 1 .. $" ) { print $_< $" + 1 - $! ? " " x $/ : $_ <= $" ? sprintf "%*d", $/, $" + 1 - $_ : $_ <= $" + $! - 1 ? sprintf "%*d", $/, abs $" - 1 - $_ : $_ == 2 * $" ? "\n" : "" foreach ( 1 .. ( 2 * $" ) ); }
    We can interpret the ternary operators as being the equivalent of a C switch() statement. The first case of the switch() prints out the leading spaces needed to maintain the pyramid shape. The second case prints out the numbers from $! down to 1. The third case prints out the numbers from 2 up to $!. The fourth case prints the final newline. The default case prints nothing.
      Quite correct. And as I said, it's a first attempt. As for the sprintf format declarations, man 3 printf (I'd be very surprised if the internal implement ation of the perl printf functions aren't just wrappers to the original libc ones) is your friend. It's a bit on the terse side (or at least the GNU manpage was that to me) but quite useful once you get used used to the style.
Re: A first attempt at obfuscation.
by tcf03 (Deacon) on Feb 18, 2005 at 22:35 UTC
    Im inspired