in reply to Collapsing a string to unique characters

Golf:55 (and no sort!)

perl -ple"local($\",@_);@_[unpack'C*',$_]=split'';$_=qq[@_]" test-stri +ngs +/034589BDFHKMNUXabcfghjlnqstuwxyz /1234589ACEGIKLMNPQRSTbdefhjklnopqstux /013589ABCIMNRTVYbcdefghjkloqtuwxy /03589BEFKLMNOPQTabcfghlmqrtuvwx +/1345689ACGKMNOQWbdghlmnoqrtuwx /234589ABDEFGHIMNORTabdfhilnqtuwxyz +/01345789ACEIMNPQTZabcefghlmqtuwx /234589ACGILMNOQUbehlmoqrstuwxyz

Unix version is one less:perl -ple'local($",@_);@_[unpack"C*",$_]=split"";$_=qq[@_]'

Two less(thanks ikegami):perl -ple'local($",@_);@_[unpack"C*",$_]=split"";$_="@_"'

Update:54: perl -ple"local(@_);@_[unpack'C*',$_]=split'';$_=join'',@_" test-strings

50: -ple"@_=();@_[unpack'C*',$_]=split'';$_=join'',@_"


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Collapsing a string to unique characters
by ikegami (Patriarch) on Jan 09, 2009 at 14:49 UTC
    Depending on platform and Perl version:
    Unix, pre 5.10: 42 -nle'@_=();@_[unpack"C*",$_]=/./g;print@_' Windows, pre 5.10: 40 -nle@_=();@_[unpack'C*',$_]=/./g;print@_ Unix, 5.10+: 40: -nlE'@_=();@_[unpack"C*",$_]=/./g;say@_' Windows, 5.10+: 38: -nlE@_=();@_[unpack'C*',$_]=/./g;say@_

      38, resp. 36 when using say instead of print

      -nle@_[unpack'C*',$_]=/./g;@_=!print@_

      Update:And 36 resp. 34:

      -nle@_[ord]=$_,for/(.)/g;@_=!print@_

      And if you're using the -E+say, you can shave off one more by leaving off the -l, at 33 strokes:

      -nE@_[ord]=$_,for/(.)/g;@_=!say@_

      Update2: And incorporating BrowserUk and JavaFan's ideas:

      # 34 strokes on Windows, and also Unix if your shell doesn't treat "!" + special -nE@_[map+ord,/./g]=/./g;@_=!say@_

      Minus 1 on all:

      Windows, pre 5.10: 39 -nlelocal@_[map+ord,/./g]=/./g;print@_

      You can leave off the -l. You don't need it for the output, as you're using say. And you don't need it for the chomp, as /./ doesn't match the newline.
Re^2: Collapsing a string to unique characters
by dwhite20899 (Friar) on Jan 09, 2009 at 14:32 UTC
    Be kind! It's still morning here, and I'm not done my tea!

    That's spectacular, but it hurts my brain...