Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

YAJAPH

by Dominus (Parson)
on Nov 11, 2000 at 00:18 UTC ( [id://41017]=obfuscated: print w/replies, xml ) Need Help??

A cut-down version of this one won second place in its category in this year's Obfuscated Perl Contest. But I'm a little bummed because the first-place winner is actually a lot easier to understand.

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ" +;sub p{ @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P +[$f|ord ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^ +[P.]/&& close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S +/;print

Hints are available from my web site. I will post the solution there at the beginning of December.

Replies are listed 'Best First'.
(Ovid) RE: YAJAPH
by Ovid (Cardinal) on Nov 11, 2000 at 00:47 UTC
    Are you referring to the rotated Mayan numerals? I know what you mean about it being easier to understand. It was my understanding that if a judge could look at an entry and get a feel for what it was doing, it was disqualified.

    I read through the winner and saw what was going on. I played around with it and really got a handle on it. While I will admit that I thought it was a beautiful obfuscation, it hardly fell in the "difficult" category. I suspect that it won because of the interesting approach.

    Frankly, I'm not a good enough Perl programmer to "get" most obfuscated code (that's the point, huh?), so if I see something I "get", I don't really think it's obfuscated.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

      Ovid wrote:
      >Are you referring to the rotated Mayan numerals?

      Right, that one. I thought it was a cute idea, but it was basically a gimmick, and the code itself was not obfuscated; it was straightforward. If I had thought of doing that I would have decided it was not interesting enough to submit.

      I don't mind getting second place, but I do wish that the program that had won had been harder to understand.

YAJAPH Solution
by Dominus (Parson) on Dec 02, 2000 at 06:46 UTC
YAJAPH Hint #01
by Dominus (Parson) on Nov 12, 2000 at 21:56 UTC
    If you think you understand what is going on in this program, ask yourself the following question:

    What is @P for? Why does it have the value it has?

    If you don't know the answer, you don't understand the program. @P is the most important data structure. Tampering with @P will break the program totally.

YAJAPH Hint #02
by Dominus (Parson) on Nov 14, 2000 at 22:13 UTC
    How is the output being printed? What is in $_ when the print statement is executed?
YAJAPH Hint #03
by Dominus (Parson) on Nov 17, 2000 at 00:48 UTC
    Since the print prints $_, and $_ contains only one character, but the program produces 32 bytes of output, clearly there are at least 32 processes involved.

    Each process does

    sleep rand(2)
    to emphasize this.

    But the output comes out in the right order even though 32 concurrent processes are each printing a single character.

    How is that accomplished?

YAJAPH Hint #04
by Dominus (Parson) on Nov 20, 2000 at 05:57 UTC
    Why are there exactly five calls to the p() function?
YAJAPH Hint #05
by Dominus (Parson) on Nov 23, 2000 at 23:25 UTC
    $q is used to index the data array @d to select which character is printed.

    How is $q computed?

YAJAPH Hint #06
by Dominus (Parson) on Nov 26, 2000 at 23:46 UTC
    "r$p" and "u$p" are used in the pipe() call as filehandle names and also as keys into the %p hash. Therefore, %p is tracking something about the filehandles.
YAJAPH Hint #07
by Dominus (Parson) on Nov 29, 2000 at 04:16 UTC
    %p is updated by the two statements:
    $P = $P[$f|ord($p{$_})&6]; $p{$_}=/ ^$P/ix?$P:close$_
    I promised back in HINT01 that @P was the most important data structure in the program. What is the significance of the index $f|ord($p{$_})&6 here?
YAJAPH Hint #08
by Dominus (Parson) on Nov 30, 2000 at 00:12 UTC
    There's no point in opening pipes if you don't read from them.

    Where is the code that reads from the pipes?

YAJAPH Hint #09
by Dominus (Parson) on Nov 30, 2000 at 19:24 UTC
    Under what circumstances is the close() call exercised?

    What is closed?

YAJAPH Hint #10
by Dominus (Parson) on Dec 01, 2000 at 05:14 UTC
    Try making a diagram of where the pipes go.
RE: YAJAPH
by arturo (Vicar) on Nov 11, 2000 at 00:23 UTC

    use the "d/l code" link that shows up at the bottom of nodes containing <code> tags. It will give you "just the code" as a text/plain doc in your browser window (unless your browser's set to d/l the text)

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

      Yeah, but it's silly to have to do that. They should break the lines at 80 characters, not 70.
        OK, I now present the exclusive Perl Monks-only verion of the program:
        @P=split//,".URRUU\c8R";sub p{@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p"; ++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|6&ord$p{$_}];$p{$_}=/ ^$P/ix?$P: close $_} keys %p} @d= split //, "\nrekcah xinU / lreP rehtona tsuJ" ;p;p;p;p;p; map{ $p{$_} =~ /^[P.]/ && close$_} %p; wait until$?; map{/^r/&&<$_>} %p;$_ = $d[$q]; sleep rand(2)if/\S/; print
        This is a setting you can change in your user preferences.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://41017]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-03-19 08:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found