Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

(Golf) Reversal

by japhy (Canon)
on May 02, 2001 at 08:38 UTC ( #77237=perlmeditation: print w/ replies, xml ) Need Help??

This looks deceptively easy. My code (which I believe is as short as possible) is 11 characters. (Perhaps this is unfair -- it's more like a "who can hit the ball where I hit it" challenge than a "who can hit the ball far" challenge.)

Goal: create a function that takes a list of strings as its arguments and returns the characters of those strings in reversed order. That's it!

print R(123); # 321 print R(12,34,56); # 654321 sub R {...} # <-- my best score: 11
More than meets the eye. I'm betting a handful of you get an answer of 14 characters, but there might be a couple who slip through and figure out the trick to save a character, and another few to get it down to 11.

japhy -- Perl and Regex Hacker

Comment on (Golf) Reversal
Download Code
Re: (Golf) Reversal
by MeowChow (Vicar) on May 02, 2001 at 08:55 UTC
    12 so far:
    sub R { ''.reverse@_ }
    Hmmm... here's an 11 character one that works on your examples, only because they are numbers:
    sub R { 0+reverse@_ }
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Ok. Now come up with an 11-character one that works for non-numbers. ;)
      Hint? I'm being a bit of a wise-ass, aren't I? ;)


      japhy -- Perl and Regex Hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://77237]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-12-27 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls