in reply to Brace For This


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.
--

Replies are listed 'Best First'.
Re: Re: Brace For This
by MeowChow (Vicar) on Apr 27, 2001 at 19:54 UTC
    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.
      --