The latest version of Acme::EyeDrops:
 http://search.cpan.org/search?dist=Acme-EyeDrops
contains five face shapes, namely:
 larry, damian, merlyn, eugene, buffy2.

A friend of mine asked: Is it possible to produce a 'pure'
(i.e. no leading eval) EyeDrop'ed program that displays
one of these faces looking in the mirror?

This intriguing problem is easy to solve if you are allowed
more than one shape, but difficult otherwise because the sightly
encoding is somewhat uncompact. And the 'pure' requirement
means running inside a regular expression, which, in turn,
means not using regular expressions and being careful with
the $_ variable (the Perl regex engine being non-reentrant).

I started with:

k.pl (82 characters):
open 0;chop,$==length,$=<$-or$-=$=for@a=<0>;
print map{$"x($--length).reverse.$/}@a

Note that EyeDrops-generated programs contain no trailing
spaces, which complicates the above program.

It is interesting to observe that using the $_ localized by for
and map seems to be OK in code running inside a regular expression
while explicitly setting $_ (as in $_ = <0>) causes all sorts of
weird crashes. Maybe a Perl internals expert could explain.

After installing Acme::EyeDrops, you can create Buffy looking
in the mirror like this:
  cd Acme-EyeDrops-1.06/demo
  perl sightly.pl -r -f k.pl -s buffy2 >b.pl
  cat b.pl        (should show Buffy's face)
  perl b.pl       (should show Buffy looking in the mirror)

I tried this for all five face shapes, producing:
  larry:   3 shapes
  damian:  2 shapes
  merlyn:  2 shapes
  eugene:  1 shapes
  buffy2:  2 shapes
Drat. Most need 2 or more shapes. What to do? You might call
this cheating, but I wrote a post processor program, pp.pl,
to append the required number of spaces to each line:

pp.pl:
@a=<>;chop@a;for$x(@a){$y=length$x;$y<$%or$%=$y}
for$x(@a){print$x.($"x($%-length$x)).$/}

With this program in place, k.pl can be simplified to:

kk.pl (36 characters):
open 0;print map{chop;reverse.$/}<0>

and Buffy looking in the mirror produced with:
  cd Acme-EyeDrops-1.06/demo
  perl sightly.pl -r -f kk.pl -s buffy2 >b.pl
  perl pp.pl b.pl >bb.pl
  cat bb.pl        (should show Buffy's face)
  perl bb.pl       (should show Buffy looking in the mirror)

This is a big improvement, producing:
  larry:   2 shapes
  damian:  1 shapes
  merlyn:  1 shapes
  eugene:  1 shapes
  buffy2:  1 shapes (shown below)

Can anyone improve the golf score of k.pl or kk.pl above?

Interestingly, if the problem is to show the face upside down,
rather than reflected, it is more easily solved:
  open 0;print reverse<0>
and easier still for self-printing:
  open 0;print<0>

/-\ndrew


                   ''=~('('.'?'                                
                .'{'.('`'|"\%").(                              
              '['^'-').('`'|'!').(                             
             '`'               | ','                           
            ).+                (  '"'                          
           ).(                 (   '`'                         
          )|+                  (   '/'                         
         )).                  (     '['                        
        ^((              '+')))      .+(                       
        '`'          |'%'      )     .+(                       
       '`'       |'.'           )     .+(                      
       '{'     ^+                (     '['                     
       )).    (                   (    '^'                     
       )^(   (                     ('`'))|                     
      '.'    )                      ) .  (                     
      (   ';') ).('['      ^'+').     (  (                     
      (  (  ((                        (  (                     
      (  (      ( (( (     ( (( (     (   (                    
      (  (       '[')       ))))      )   )                    
      )   )                        )))    )                    
      )    )))                     )      )                    
      ))      ^       (   (        (     ((                    
      ')'      )        )          )    )))                    
       .('`'|')'                   ).("\`"|                    
       '.').('['    ^('/')).(     '{'^'[')                     
       .('`'|'-')     .('`'     | ('!')).(                     
       '['^'+').''.            (  '\\').+                      
       '{'.('`'|'#')          .   (('`')|                      
       '(').('`'|'/' )      .     (('[')^                      
       '+').';'.('['     ^        ')').( (                     
       '`')|"\%").(              '['^'-'   )                   
       .('`'|'%').(              '['^')'     )                 
        .('['^'(').             ('`'|'%'     )."\.".           
        '\\'.('$').             '/'.''.      (      '\\').+    
  '}'.'<'.(('^')^(            ( "\`")|       (             (   
 (    ( '.')))))). (        (   '>'))        .              (  
(     ( '!'))^'+')   .   (     '"').         (              (  
(     '}'))).')')       ;     ($:)           =              (  
(    '.'))^"\~";        (                    (               ( 
(     ($~)))))          =                    (               ( 
(     ( '@')                                 )               ) 
)     |                                      (               ( 
(     (                                      (               ( 
(     (                                      (      (         (
(     (                                      (      (         (
(     (                                      (     (          (
(     (                                      (     (          (
(     '(')))))))))))))))))))))))))));$^=(')')^    (           (
(    '[')));$/='`'|'.';$_='('^'}';$,='`'|('!');$\=            (
(    ')'))^'}';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/=           (
(   '`'))|'.';$_='('^'}';$,='`'|'!';$\=')'^('}');$:=          (
(   '.'))^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$_='('         ;

Reply via email to