Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Golf for unique digits

by BrowserUk (Patriarch)
on Jan 09, 2013 at 11:40 UTC ( [id://1012450]=note: print w/replies, xml ) Need Help??


in reply to Golf for unique digits

C:\test>perl -nlE"s[(.)(?=.*?\1)][]g;say length;" 1987 4 2013 4 2113 3 122398723456321467891356178653534 9 1111111111111111 1 121212121212121212121212 2

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
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.

Replies are listed 'Best First'.
Re^2: Golf for unique digits (17)
by tye (Sage) on Jan 09, 2013 at 18:42 UTC

      This seems to work just as well?

      perl -nlE"say s/(.)(?!.*\1)//g"

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

      tye++ ... but I'm stuck to understand how it works?

      According to perlop:

      Searches a string for a pattern, and if found, replaces that pattern with the replacement text and returns the number of substitutions made.

      How does the number of substitutions made equate to the number of characters left after the substitutions?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.
        >How does the number of substitutions made equate to the number of characters left after the substitutions?

        (?!..) = not followed by!

        every cipher is exactly once the last of it's kind! =)

        Cheers Rolf

Re^2: Golf for unique digits
by AnomalousMonk (Archbishop) on Jan 09, 2013 at 13:03 UTC

     .*? can be  .* saving one whole character!

      And s[][] -> s/// for another :) Habits!


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      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.

         s/// — A-ha!

Re^2: Golf for unique digits
by choroba (Cardinal) on Jan 09, 2013 at 13:36 UTC
    You can drop the final semicolon, too. How comes there are not two of them? :-)
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1012450]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found