Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: (Golf) Cryptographer's Tool #1

by srawls (Friar)
on Jun 20, 2001 at 00:53 UTC ( #89813=note: print w/replies, xml ) Need Help??

in reply to (Golf) Cryptographer's Tool #1

Here's my shot at it; 68 chars:
sub c { ($_,$a)=@_; map{$h{$_}?$h{$_}:do{$h{$_}=(split//,$a)[$i++]."\0"}}/./g }


Here's another at 66. This one takes a completely different approach--it removes all duplicates of letters(the long part), then does a simple translation on them (the easy part). Here it is:

sub c { ($_,$a)=@_;$b=$_; 1 while$b=~s/(.)(.*?)\1/$1$2/g; eval"y/$b/$a/"; $_ }

Update2:Good catch tilly. This makes it too long to contend, but here's the revised version:

sub c { ($_,$a)=@_;$b=$_; 1 while$b=~s/(.)(.*?)\1/$1$2/g; eval"y/\Q$b\E/\Q$a\E/"; $_ }

The 15 year old, freshman programmer,
Stephen Rawls

Replies are listed 'Best First'.
Re (tilly) 2: (Golf) Cryptographer's Tool #1
by tilly (Archbishop) on Jun 20, 2001 at 03:25 UTC
    What if the searchlist contains /? Or a -?
(Vynce) Re: (srawls:update 2) Re: (Golf) Cryptographer's Tool #1
by Vynce (Friar) on Jun 20, 2001 at 12:50 UTC

    you can, of course, take out the \E's.

    still not a particular contender, though.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://89813]
[1nickt]: choroba I'm trying to make a cpanfile for pm-cb ... how to handle the MCE vs Thread::Queue question? Maybe with on 'build' => sub { if ($threaded_perl) { requires 'Thread::Queue' } else { requires 'MCE' } ?

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2017-10-18 13:02 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (244 votes). Check out past polls.