Randal's one-liners

224 views
Skip to first unread message

Tom Neff

unread,
Feb 28, 1990, 9:26:32 AM2/28/90
to
Humorous though the suggestion may be, I do think Randal's one-line
"Just another Perl hacker" obfuscated Perl scriptlets would make a
very good test suite for new releases of Perl as well as at install
time. Nor does he have to be the only contributor - anyone can
put something together. (Wait for mine.)

Tom Neff

unread,
Feb 28, 1990, 5:45:45 PM2/28/90
to
This is three lines out of courtesy to newsreading software -- it
runs fine as one long line.. :-)

@a=split(//,'1111211111131223311361214223121412311341121111222123616111111122'.
'21233212615112114212321211121111222123321120');for$r(@a){for(1..$r){vec($s,$i,
1)=$v;$i++;}$v^=1;}print"$s\n";

--
War is like love; it always \%\%\% Tom Neff
finds a way. -- Bertold Brecht %\%\%\ tn...@bfmny0.UU.NET

J Greely

unread,
Mar 1, 1990, 1:27:25 AM3/1/90
to
In article <15...@bfmny0.UU.NET> tn...@bfmny0.UU.NET (Tom Neff) writes:
>This is three lines out of courtesy to newsreading software -- it
>runs fine as one long line.. :-)
[entry in the .sig wars deleted]

I haven't really been keeping track of the schemes. Has this one been
done?

print reverse(split(/!?/,join(' ',sort split(/ /,"tsuJ rehtona lrep ,rekcah"))));

--
J Greely (jgr...@cis.ohio-state.edu; osu-cis!jgreely)
--
J Greely (jgr...@cis.ohio-state.edu; osu-cis!jgreely)

Ran Ever-Hadani

unread,
Mar 1, 1990, 6:40:10 AM3/1/90
to
I tried to troff the slides posted here, and did not succeed.

I did not attempt to solve the problem (I don't have the time).
Could someone archive the slides in Postscript format, as was
done with the Perl Reference Guide?

Thanks

-- Ran
-----------------------------------------------
Reply-To: cre...@taux01.nsc.com (Ran Ever-Hadani)
Disclaimer: The above is to be attributed to me only, not to any organization.
Apology: Bad English. E-mailed spelling and style corrections are welcome.

Paul E. Maisano

unread,
Mar 1, 1990, 8:07:02 PM3/1/90
to
Here's my contribution:

print join(' ',grep(s/.(.*)i(.*)/\2er\1/||1,sort split(/[v-z]/,"fliPweianothyo,ihack\nvJust")));

------------------
Paul E. Maisano
Australian Artificial Intelligence Institute
1 Grattan St. Carlton, Vic. 3053, Australia
Ph: +613 663-7922 Fax: +613 663-7937
Email: p...@aaii.oz.au UUCP: {uunet,mcsun,ukc,nttlab}!munnari!aaii.oz.au!pem

Randal Schwartz

unread,
Mar 2, 1990, 2:07:50 AM3/2/90
to
In article <11...@frankland-river.aaii.oz.au>, pem@frankland-river (Paul E. Maisano) writes:
| print join(' ',grep(s/.(.*)i(.*)/\2er\1/||1,sort split(/[v-z]/,"fliPweianothyo,ihack\nvJust")));

"Where does he *get* those *wonderful* toys???" -- The Joker
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| mer...@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

Larry Wall

unread,
Mar 2, 1990, 3:12:50 PM3/2/90
to
In article <15...@bfmny0.UU.NET> tn...@bfmny0.UU.NET (Tom Neff) writes:
:This is three lines out of courtesy to newsreading software -- it

:runs fine as one long line.. :-)
:
:@a=split(//,'1111211111131223311361214223121412311341121111222123616111111122'.
:'21233212615112114212321211121111222123321120');for$r(@a){for(1..$r){vec($s,$i,
:1)=$v;$i++;}$v^=1;}print"$s\n";

Or, more concisely,

for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
{for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

And a special version just for Randal:

grep(do{for(ord){$i+=$_%8;grep(vec($s,$i++,1)=1,5..($_>>3||print"$s\n"));}},
(@x=split(//,"))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)\7")));

Larry

Tom Neff

unread,
Mar 2, 1990, 4:49:57 PM3/2/90
to
In article <72...@jpl-devvax.JPL.NASA.GOV> lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
> for(split(//,'))*))91...

Under 2.0.1.3, the split() function didn't work as the argument of a for()
clause. I tried it every which way. Assigning to an intermediate was needed.

I confirm this is fixed with 2.0.1.4 which is presumably where Larry tested
his optimization of my signature hack...

Also I notice that some packages (e.g. 'dumpvar.pl') which lacked a closing
'1;' *will* now make the 'do' statement fail. Be warned!

Randal Schwartz

unread,
Mar 2, 1990, 5:01:59 PM3/2/90
to

Larry... gettin' a little too much caffeine lately?

Or do you have all sortsa spare time now that Patch 9 (10,11,12...
sigh) from Outer Space is complete?

So, when are we going to have the official Obfuscated Perl contest
announcement? :-)

By the way, that last one didn't print anything for me. 'course, I'm
still on Patch 6... but'll be up to 12 by the weekend (hopefully).

$_=",rekcah lreP rehtona tsuJ";1while(s/(.*)(.)/(print$2),$1/eg);

Sean Casey

unread,
Mar 2, 1990, 5:59:55 PM3/2/90
to

You're warped, man. Really warped :-).


Sean

--
*** Sean Casey se...@ms.uky.edu, se...@ukma.bitnet, ukma!sean
*** "Well, heck's farr, Jim, it gives mah computer sumthin' to do when
*** Ah'm out brandin' capacitors." -DM

Mark Moraes

unread,
Mar 2, 1990, 6:13:25 PM3/2/90
to
>So, when are we going to have the official Obfuscated Perl contest
>announcement? :-)

The thought crossed my mind. Then, a friend pointed out that
"obfuscated perl" is a redundant phrase... :-)

Dave Platt

unread,
Mar 3, 1990, 11:25:11 PM3/3/90
to
> Or, more concisely,
>
> for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
> {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";
>
> And a special version just for Randal:
>
> grep(do{for(ord){$i+=$_%8;grep(vec($s,$i++,1)=1,5..($_>>3||print"$s\n"));}},
> (@x=split(//,"))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)\7")));
>
> Larry

"He's creayted a MONstah!" (in the proper sepulchral tones, of course).

Some time ago, a friend related reading a comment... "If awk is the
Swiss Army knife of Unix programming, perl is the Swiss Army chainsaw!"
I think this understates the case... does anybody know if the Swiss Army
has a shmoo as a mascot?

;-}


--
Dave Platt VOICE: (415) 493-8805
UUCP: ...!{ames,apple,uunet}!coherent!dplatt DOMAIN: dpl...@coherent.com
INTERNET: coherent!dpl...@ames.arpa, ...@uunet.uu.net
USNAIL: Coherent Thought Inc. 3350 West Bayshore #205 Palo Alto CA 94303

Daniel Ehrlich

unread,
Mar 5, 1990, 1:18:27 PM3/5/90
to

Larry> In article <15...@bfmny0.UU.NET> tn...@bfmny0.UU.NET (Tom Neff) writes:
Larry> :This is three lines out of courtesy to newsreading software -- it
Larry> :runs fine as one long line.. :-)
Larry> :
Larry> :@a=split(//,'1111211111131223311361214223121412311341121111222123616111111122'.
Larry> :'21233212615112114212321211121111222123321120');for$r(@a){for(1..$r){vec($s,$i,
Larry> :1)=$v;$i++;}$v^=1;}print"$s\n";

Larry> Or, more concisely,

Larry> for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
Larry> {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

Larry> And a special version just for Randal:

Larry> grep(do{for(ord){$i+=$_%8;grep(vec($s,$i++,1)=1,5..($_>>3||print"$s\n"));}},
Larry> (@x=split(//,"))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)\7")));

Larry> Larry

Could one of the perl gurus take a moment to enlighten a novitiate perl
hacker as to how or why any or all of these examples do what they do? Other
than that they all print out 'Just another Perl hacker,'.

Thanks.
--
Dan Ehrlich <ehr...@cs.psu.edu>
Voice: +1 814 863 1142 FAX: +1 814 865 3176

Larry Wall

unread,
Mar 5, 1990, 8:48:46 PM3/5/90
to
In article <E4uj=r...@cs.psu.edu> ehr...@cs.psu.edu (Daniel Ehrlich) writes:
: Could one of the perl gurus take a moment to enlighten a novitiate perl

: hacker as to how or why any or all of these examples do what they do? Other
: than that they all print out 'Just another Perl hacker,'.

It's all magic. :-)

Here's Tom's version, expanded and commented:

@a=split(//,'1111211111131223311361214223121412311341121111222123616111111122'.
'21233212615112114212321211121111222123321120'); # make array of chars

foreach $r (@a) { # foreach digit above
foreach $_ (1 .. $r) { # just count to $r: for ($_ = 1; $_ <= $r; $_++)
vec($s,$i,1)=$v; # add a 0 or a 1 bit to string $s
$i++; # increment bit location in bit vector
}
$v ^= 1; # flip between 0 and 1 using xor
}
print"$s\n"; # print the resultant string

The primary thing you have to know is that vec() can set any arbitrary bit
in a bitmap that happens to be held in a string, and Tom is just iterating
over all the bits of the output string, setting the right number of 0 bits,
1 bits, 0 bits, 1 bits, etc. I confess it's so simple I had to stare at
it a loooong time to figure it out...

Here's my first version. The chief difference is that each character of
our data array now encodes both the count of 0 bits and the count of 1 bits.
The 0 bits are encoded in the lowest three bits, and the 1 bits are encoded
in the next three bits. The whole character has 32 added to it to make
it a printable character. Note that we don't have to worry about subtracting
out the 32 when extracting the lower 3 bits.

foreach $_ ( # make array of funny chars


split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"')

) {

foreach $_ (ord $_) { # funny way to say $_ = ord($_)
$i += $_ & 7; # skip right amount of zero bits
grep( # equivalent to a foreach
vec($s,$i++,1)=1, # set the correct 1 bit
1 .. ($_ >> 3) - 4 # same as 1 .. (($_ - 32) >> 3)
);
}
}
print"$s\n";

The last way is just an obfuscation of the previous one. It uses greps
in place of the two outer foreach's, which is why it was especially for
Randal, our chief grep nut. Note that the order of arguments changes
when we switch to using grep. The other two changes are that, instead of
subtracting 4 from the $_ >> 3, we just add it algebra-style to the left
argument of .. and end up with a 5 there. And the print statement is
tucked away there in the middle, ready to go off when the second three
bits happen to equal 0, which the \7 on the end of the magic string
provides.

grep( # iterate over array of chars made by second argument
do { # because grep can't take an sequence of statements directly
for (ord) { # foreach $_ (ord $_)
$i += $_ % 8; # same as $_ & 7
grep(
vec($s,$i++,1)=1,
5 .. ($_ >> 3 || print "$s\n")
);
}
},
(@x = # assignment works around a perl bug! Eeek!!


split(//,"))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)\7")
)
);

Disgusting, ain't it? Well, you asked...

Larry

Andrew Vignaux

unread,
Mar 6, 1990, 6:07:32 AM3/6/90
to
I'm afraid I can't get my submission down to 1 line (excluding data) :-(
Can anyone help?

@l = split (/(..)/,'1a7r4J1n0a7e7c1o8n248o1t4u8v4s7.207l27547a7n7g1h'.
'0 511e3h7.8i564t3a6P1r7p8c8e6e3c3k7e3e533r7r286r6l4 6 1 8,7l7 3,');
srand; $_=3*int(rand(2))+2; /^$_/;
foreach (split(//,&g)) {/^$_/;print &g;} print "\n";
sub g {join('',grep(s/^.//,grep(//,@l)));}

The interesting bit is the "grep(//,@l)". Is this a "feature" ;-)
Can anyone exploit it in a real script?

Andrew
--
Domain address: Andrew....@comp.vuw.ac.nz

Tom Christiansen

unread,
Mar 6, 1990, 7:56:58 AM3/6/90
to
In article <34...@taux01.UUCP> cre...@taux01.nsc.com (Ran Ever-Hadani) writes:
|I tried to troff the slides posted here, and did not succeed.
|I did not attempt to solve the problem (I don't have the time).
|Could someone archive the slides in Postscript format, as was
|done with the Perl Reference Guide?

[Sorry to take so long to answer; my news feed just came back after
a week-long hiatus.]

I've heard that some of the vintage AT&T troffs can't handle some of
the motion commands; apparently I've inadvertently used a common but not
ubiquitous addition to troff. Sorry about that. Included in the
distribution were three macro headers: one for troff, one for nroff, and
one for pure ASCII. If the first doesn't work for you, try one of the
others. The ASCII one should be unadulterated text. The troff is just
fluff; the others should have other the information in them.

I don't have postscript.

--tom
--

Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist
Convex Computer Corporation tch...@convex.COM
"EMACS belongs in <sys/errno.h>: Editor too big!"

Larry Wall

unread,
Mar 8, 1990, 6:48:18 PM3/8/90
to
In article <1990Mar6.1...@kaukau.comp.vuw.ac.nz> a...@comp.vuw.ac.nz (Andrew Vignaux) writes:
: I'm afraid I can't get my submission down to 1 line (excluding data) :-(

: Can anyone help?
:
: @l = split (/(..)/,'1a7r4J1n0a7e7c1o8n248o1t4u8v4s7.207l27547a7n7g1h'.
: '0 511e3h7.8i564t3a6P1r7p8c8e6e3c3k7e3e533r7r286r6l4 6 1 8,7l7 3,');
: srand; $_=3*int(rand(2))+2; /^$_/;
: foreach (split(//,&g)) {/^$_/;print &g;} print "\n";
: sub g {join('',grep(s/^.//,grep(//,@l)));}

You want it in one line? Does it have to fit in 80 columns? :-)

I really liked your "holographic" approach. I had to stare at it quite
some time for things to resolve. I thought I was going crazy when it
printed out something different when I ran it on a different machine.

: The interesting bit is the "grep(//,@l)". Is this a "feature" ;-)


: Can anyone exploit it in a real script?

Yes, it's a feature. Any null pattern (except in a split) just refers
back to the last real pattern match, ala ed and sed.

I imagine this would be one mechanism for getting around the problem
mentioned earlier of having run-time patterns that you don't want to
recompile every iteration of a grep, but that you want to change
occasionally, which rules out /$pat/o (except in an eval).

Larry

Reply all
Reply to author
Forward
0 new messages