Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

(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

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@_ }
                   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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-09-24 08:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found