Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: (Golf) RNA Genetic Code Translator

by no_slogan (Deacon)
on Jul 06, 2001 at 02:48 UTC ( [id://94323]=note: print w/replies, xml ) Need Help??


in reply to (Golf) RNA Genetic Code Translator

130 characters:
$_="KNNKtIIIMRSSRQHHQplr.YY.sLFFL.CCWEDDEavg";s/[a-z]/uc$&x4/eg;@x=/./ +g;join"",@x[map{$x=0;$x=$x*4|6&ord for/./g;$x/2}pop=~/.../g]

Replies are listed 'Best First'.
Re: Re: (Golf) RNA Genetic Code Translator
by srawls (Friar) on Jul 06, 2001 at 03:54 UTC
    I can shave 4 chars off of that:
    $_="KNNKtIIIMRSSRQHHQplr.YY.sLFFL.CCWEDDEavg";s/[a-z]/uc$&x4/eg; join"",(/./g)[map{$x=0;$x=$x*4|6&ord for/./g;$x/2}pop=~/.../g]

    The 15 year old, freshman programmer,
    Stephen Rawls

Re: Re: (Golf) RNA Genetic Code Translator
by MeowChow (Vicar) on Jul 08, 2001 at 00:44 UTC
    Bending the spec a bit at 123 (regarding treatment of leftover base pairs):
    sub f { $_=pop;y/ACUG/0123/;s|(.)(.)(.)|(map{ord>91?uc:(),uc} 'KnKttiIMRsRQhQppllrr.y.ssLfL.cWEdEaavvgg'=~/./g)[$1*16+$2*4+$3]|eg;$_ }
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Stunning, to say the least, but what is more stunning is the amateurish oversight that I made myself when posting my entry. How could I have not used the range feature of tr? I feel silly, but at least I'm not alone:
      sub f { $_=pop;y/ACUG/0-3/;s|(.)(.)(.)|(map{ord>91?uc:(),uc} 'KnKttiIMRsRQhQppllrr.y.ssLfL.cWEdEaavvgg'=~/./g)[$1*16+$2*4+$3]|eg;$_ }
      I was looking at my entry, trying to save a few strokes, motivated by scain's Benchmarks posted below. It was immediately obvious how to save a few strokes, now that I'm awake and caffinated and all. Revised, mine ended up at 133, still a ways off of MeowChow at the new and improved 122 posted above:
      sub f{ $_=pop;y/UCAG/0-3/;s/(.)(.)(.)/substr "FFLLSSSSYY..CC.WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG", $1<<4|$2*4|$3,1/ge;s/\d//g;$_ }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://94323]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-29 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found