Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: number of unique characters in a string

by pfaut (Priest)
on Mar 01, 2003 at 04:10 UTC ( [id://239640]=note: print w/replies, xml ) Need Help??


in reply to number of unique characters in a string

sub f { my $l = ''; my $u; for (sort split(//,$_[0])) { $u++,$l=$_ if ($_ ne $l); } return $u; }

Update: I posted this because it was faster than a hash based solution but OM_Zen's idea with rob_au's adjustment is even faster. I'd bench merlyn's Inline::C version, but I don't have Inline::C installed...

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-24 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found