Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Unique Character

by ww (Bishop)
on Feb 02, 2014 at 00:11 UTC ( #1073007=note: print w/ replies, xml ) Need Help??


in reply to Unique Character

We agree that there are 19 characters in the string... but your definition/usage of "unique" is indeed made very fuzzy when you say "I should get 19 characters total with 3 unique characters." I don't see how you get there:

arabic digit indicates instance of a char' "x" indicates no repetition/dupe (6); and roman numerals indicate distinct repeated chars (VI) AT THE FIRST +REPEAT my $str = "PERL MONKS ROCKS!!!"; P 1 x E 1 x R 1 I L 1 x 1 repeated later M 1 x O 1 repeated later N 1 x K 1 repeated later S 1 repeated later 2 II R 2 I O 2 III C 1 X K 2 IV S 2 V ! 1 VI ! 2 VI ! 3 VI
Come, let us reason together: Spirit of the Monastery


Comment on Re: Unique Character
Download Code
Re^2: Unique Character
by Latnam (Novice) on Feb 02, 2014 at 03:42 UTC
    Thanks for pointing that out to me ww about the unique characters. I used my phone a friend, and they explained to me what my professor wants. The unique characters he wants is how often a character is repeated. Such as if I used Jim Doe. There would be a total of 8 unique characters. If I used John Doe. there would still be 8 unique characters due to the o was already counted.
      This will do the trick:
      use Modern::Perl; my $string = "Perl Monks Rocks!!!"; my %chars; for ( split '', $string ) { $chars{ lc $_ }++ } my @uniques = sort keys %chars; say scalar @uniques, ": @uniques";

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-08-23 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls