Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thirty Two Camels

3 views
Skip to first unread message

Andrew Savige

unread,
May 15, 2002, 10:40:23 PM5/15/02
to f...@perl.org
A friend of mine showed me:
http://www.thinkgeek.com/stuff/docs/perl-camel-source.shtml
a camel-shaped program that prints four camels when run, and
asked could I do better using CPAN Acme::EyeDrops module.

Well, I don't know about better, but I could not restrain
myself from trying something similar.

The EyeDrops-generated camel.pl, shown below, can generate
thirty two different camels as follows:

perl camel.pl normal camel
perl camel.pl q quine (program prints itself)
perl camel.pl m mirror (camel looking in the mirror)
perl camel.pl i inverted camel
perl camel.pl u upside-down camel
perl camel.pl r rotated camel

You can further combine the above options, each combination
producing a different camel, for example:

perl camel.pl uri

The 32 possible combinations are:

"" q r u m i
qr qu qm qi ru rm ri um ui mi
qru qrm qri qui qum qmi rum rui rmi umi
qrum qrui qumi qrmi rumi
qrumi

camel.pl was generated from this program, gencamel.pl:

use Acme::EyeDrops qw(sightly);
my $prog = sightly( { Regex => 1,
Shape => 'camel',
SourceString => <<'END_SRC_STR' } );
$:=pop||'';open$%;chop(@;=<0>);$:=~/r/&&(@;=map{$-=$_+$_;join"",
map{substr$_,$-,1}@;}$%..$;[8]=~y;;;c/2);$:!~/q/&&y,!-~,#,,$:=~/m/
&&($_=reverse),$:=~/i/&&y, #,# ,,print$_.$/for$:=~/u/?reverse@;:@;
END_SRC_STR
my @a = split(/\n/, $prog);
my $max = 0; length > $max and $max = length for @a;
$_ .= ' ' x ($max - length) for @a; $\ = "\n";
print ' ' x ($max+2); print " $_ " for @a; print ' ' x ($max+2);

with the command:

perl gencamel.pl >camel.pl

I had to work quite hard to make the source program small enough to
fit into a single camel (and it won't fit into a single `/anick), so
I would be delighted if any golfers out there can further shorten:

$:=pop||'';open$%;chop(@;=<0>);$:=~/r/&&(@;=map{$-=$_+$_;join"",
map{substr$_,$-,1}@;}$%..$;[8]=~y;;;c/2);$:!~/q/&&y,!-~,#,,$:=~/m/
&&($_=reverse),$:=~/i/&&y, #,# ,,print$_.$/for$:=~/u/?reverse@;:@;

Enjoy,
/-\ndrew


camel.pl:
(Save all text between ----- lines below, including
leading and trailing space-filled lines)
-------------------------------------------------------------------

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

-------------------------------------------------------------------

Keith C. Ivey

unread,
May 15, 2002, 11:28:22 PM5/15/02
to f...@perl.org
Andrew...@ir.com <Andrew...@ir.com> wrote:

> You can further combine the above options, each combination
> producing a different camel, for example:
>
> perl camel.pl uri

which produces a large, bearded camel with a ponytail, glasses,
and a tie-dyed T-shirt.

--
Keith C. Ivey <kci...@cpcug.org>
Washington, DC

Andrew Savige

unread,
May 23, 2002, 4:41:21 AM5/23/02
to f...@perl.org
Some brilliant golfing from Mtv Europe and Ronald J Kimball has
allowed me to increase the number of camels from 32 to 128.

There are now seven options:

perl camel.pl normal camel
perl camel.pl q quine (program prints itself)
perl camel.pl m mirror (camel looking in the mirror)
perl camel.pl i inverted camel
perl camel.pl u upside-down camel
perl camel.pl r rotated camel

perl camel.pl h horizontally-squashed camel
perl camel.pl v vertically-squashed camel

The above options can be combined, for example:

perl camel.pl hv small camel

Here is the new generator program, gencamel.pl:

use Acme::EyeDrops qw(sightly);
my $src = <<'END_SRC_STR';
$~=uc pop;open$%;chop(@~=<0>);$~=~R&&(@~=map{$-=$_+$_;
join'',map/.{$-}(.)/,@~}$%..33);$|--&$~=~H&&next,
$~!~Q&&y,!-~,#,,$~=~I&&y~ #~# ~,$~=~M&&($_=reverse),
print$~=~V?/(.).?/g:$_,$/for$~=~U?reverse@~:@~
END_SRC_STR
$src =~ tr/\n//d;


my $prog = sightly( { Regex => 1,
Shape => 'camel',

SourceString => $src } );


my @a = split(/\n/, $prog);
my $max = 0; length > $max and $max = length for @a;
$_ .= ' ' x ($max - length) for @a; $\ = "\n";
print ' ' x ($max+2); print " $_ " for @a; print ' ' x ($max+2);

You can create camel.pl (shown below) with:

perl gencamel.pl >camel.pl

As always, any golfing improvements to:

$~=uc pop;open$%;chop(@~=<0>);$~=~R&&(@~=map{$-=$_+$_;
join'',map/.{$-}(.)/,@~}$%..33);$|--&$~=~H&&next,
$~!~Q&&y,!-~,#,,$~=~I&&y~ #~# ~,$~=~M&&($_=reverse),
print$~=~V?/(.).?/g:$_,$/for$~=~U?reverse@~:@~

are most welcome.

Enjoy,
/-\ndrew


camel.pl:
(Save all text between ----- lines below, including
leading and trailing space-filled lines)

--------------------------------------------------------------------



''=~('('.'?'
.'{'.( '`'|'%').("\["^
'-').('`'| '!').('`'|',').'"'

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

.''. ("\["^ ')') .''.
('[' ^(( '(') )).(
'`'| '%' ).+ (((
((( ((( ((( (((
((( ((( ((( (((
((( ((( ((( ((
(( '\\')) ))
)) ))))) ))
)) )))))))) ))
))) )))) ))))) ))

).+ ('@'). '~'. ':'
.''. '\\'.'@' .(( '~')
).'"'. ('}').
')');$:= '.'^'~'

--------------------------------------------------------------------

Alistair McGlinchy

unread,
May 23, 2002, 12:41:41 PM5/23/02
to f...@perl.org, Andrew...@ir.com

Wow! That is very cool. Although the -q flag used with any other option
isn't really a quine.

D:\>perl d:\camel.pl -qr | perl
syntax error at - line 2, near "."
Execution of - aborted due to compilation errors.

Perhaps this should be a future enhancement that camel.pl outputs a quine
(or null in the case of inverts( even if it's not the original camel code
:-)

Of course when I use my IDE to view the code, the syntax colouring is
completely wrong. Do any of you have IDE's that actually colour correctly
and can find the real matching brackets? [ BTW That was not an invitation
to start a religous war. ] Then again with code like this I wonder whether
Gimp would be a better IDE. :-)

Find the matching bracket is certainly is a non trivial function. Anyone
care to show me an elegant solution?

Alistair
> ----------------------------------------------------------------------
> Alistair McGlinchy, alistair....@marks-and-spencer.com
> Sizing and Performance, Central IT, ext. 5012, ph +44 20 7268-5012
> Marks and Spencer, 3 Longwalk Rd, Stockley Park, Uxbridge UB11 1AW, UK


-----------------------------------------------------------------------


Registered Office:
Marks & Spencer p.l.c
Michael House, Baker Street,
London, W1U 8EP
Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422
Facsimile (020) 7487 2670

www.marksandspencer.com

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.

The registered office of Marks and Spencer Financial Services Limited, Marks and Spencer Unit Trust Management Limited, Marks and Spencer Life Assurance Limited and Marks and Spencer Savings and Investments Limited is Kings Meadow, Chester, CH99 9FB.

0 new messages