First monk to figure out my encoding scheme wins a lifetime supply of cherry pies.

#!/usr/bin/perl -w use strict; @[=[[[[[[]]],[[]]],[[[]],[]],[[]]],[[[[[]]],[[]]], [[[[]]],[]],[[[[]]]],[[[]]],[]],[[[[[]]],[[]]],[ [[[]]],[]],[[[[]]]],[[]],[]],[[[[[]]],[[]]],[[ [[]]],[]],[[[[]]]],[[[]]]],[[[[[]]],[]]],[[[ [[]]],[[]]],[]],[[[[[]]],[[]]],[[[[]]],[]] ,[[[]],[]],[[[]]],[[]]],[[[[[]]],[[]]],[ [[[]]],[]],[[[]],[]],[[[]]],[[]],[]],[ [[[[]]],[[]]],[[[[]]],[]],[[[[]]]],[ [[]]]],[[[[[]]],[[]]],[[[[]]],[]], [[[]],[]]],[[[[[]]],[[]]],[[[[]] ],[]],[[[]]],[]],[[[[[]]],[[]] ],[[[[]]],[]],[[[[]]]],[[]]] ,[[[[[]]],[]]],[[[[[]]],[[ ]]],[[[[]]]]],[[[[[]]],[ []]],[[[[]]],[]],[[[]] ],[]],[[[[[]]],[[]]] ,[[[[]]],[]],[[[[] ]]],[[]]],[[[[[] ]],[[]]],[[[[] ]],[]],[[[]] ,[]],[[[]] ]],[[[[[ ]]],[] ]],[ [[[ []] ],[[] ]],[[[] ],[]]],[[ [[[]]],[[]] ],[[[[]]],[]] ,[]],[[[[[]]],[ []]],[[[[]]],[]], [[]],[]],[[[[[]]],[ []]],[[[[]]],[]],[[[] ],[]],[[]],[]],[[[[[]]] ,[[]]],[[[[]]],[]],[[[]]] ,[]],[[[[[]]],[[]]],[[[[]]] ,[]],[[[[]]]],[[]]],[[[[]],[] ],[[]]]];sub _{my$o=0;$o+=2 **_ ($_)for@{shift,};$o}print chr _$_ for @{@ [[$ []}
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Brace For This
by jmcnamara (Monsignor) on Apr 27, 2001 at 14:42 UTC

    Very nice.

    Here's what your code looks like:
    #!/usr/bin/perl -w use strict; @[=[ [ [[[[]]], [[]]], [[[]], []], [[]] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[[]]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[[]]] + ], [ [[[[]]], []] + ], [ [[[[]]], [[]]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]], []], [[[]]], [[]] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]], []], [[[]]], [[]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[[]]] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]], []] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[]] + ], [ [[[[]]], []] + ], [ [[[[]]], [[]]], [[[[]]]] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[]] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]], []], [[[]]] + ], [ [[[[]]], []] + ], [ [[[[]]], [[]]], [[[]], []] + ], [ [[[[]]], [[]]], [[[[]]], []], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]], []], [[]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[]]], [] + ], [ [[[[]]], [[]]], [[[[]]], []], [[[[]]]], [[]]], [[[[]], []], [[]] + ] ]; sub mysub { my $count = 0; $count += 2**mysub($_) for @{ shift() }; $count; } print chr mysub $_ for @{ @[[$[]}
    The array @[ has one arrayref for each of the characters of "Just Another Perl Hacker". You are generating the character index from the number of sub-arrayrefs and elements counted recursively.

    I particularly liked this:     @[[$[] $[ hardly ever gets a airing these days. Strangely, this throws a warning:     @[[0]
    One cherry pie would be a lifetimes supply for me. ;-)

    John.
    --

      You're very close, but you forgot or missed an important detail:

      You are generating the character index from the number of sub-arrayrefs and elements counted recursively.

      At the risk of being pedantic, not exactly :-)

         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

        At the risk of being pedantic, not exactly

        You are right. I should have been more explicit.

        The algorithm is a binary encoding of the ordinal values of the characters based on the accumulated level of recursion. For example the letter "J" is encoded as follows:
        [ [[[[]]], [[]]], [[[]], []], [[]] ] Adding brackets to highlight the nesting of the arrayrefs: [ ([ ([[[ ]]]) , ([[ ]])) ]), ([ ([[ ]]) , ([ ]) ]), ([ ([ ] +) ]) ] 4 2 2 1 1 This gives: = 2**(4+2) +2**(2+1) +2**(1) = 2**(6) +2**(3) +2**(1) = 1001010b = 74 = ord('J');
        Clever and artistic. ;-)

        John.
        --