http://www.perlmonks.org?node_id=77237

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

Replies are listed 'Best First'.
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