in reply to Golf: string complement

40 strokes (after fixing the \Q \E bug)
my $string = 'abcde'; sub invert { #234567890123456789012345678901234567890 join"",grep/[^\Q$_[0]\E]/,map{chr}1..255 } print invert($string);

UPDATE: Finally, I did it! 37 strokes. :)

my $string = 'defg'; sub invert { #234567890123456789012345678901234567890 join'',grep/[^\Q@_\E]/,map{chr}1..255 } print invert($string);

Dave

Replies are listed 'Best First'.
Re:^2 Golf: string complement
by cLive ;-) (Prior) on May 15, 2004 at 23:27 UTC
    How about we lose another 7 characters :)
    sub invert { #23456789012345678901234567890 grep/[^\Q@_\E]/,map{chr}1..255 }

    cLive ;-)

    updare - to summarize response to BrowserUK's comment - calling the sub in scalar context will automatically join the list into a scalar. Is that cheating? maybe :) - never mind, I was running the wrong test script lol :)

      Problem: That will return a list of characters, not a string.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
        But, when you print, it forces scalar context. The output of the print statement is the same. Same if you assigned result of sub to a scalar explicitly:
        my $result = invert($string);
        is the same with or without the join.

        .02

        cLive ;-) - see above