Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

(tye)Re: Counting number of characters in a string

by tye (Sage)
on Mar 13, 2001 at 02:35 UTC ( #63996=note: print w/replies, xml ) Need Help??

in reply to Counting number of characters in a string

my $count= 0; for(0..255){ my $c= pack "C", $_; $count += () = $str =~ /\Q$c\E/g; }

Warning! This probably yields an inaccurate count for Unicode strings.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
(tye)Re2: Counting number of characters in a string
by tye (Sage) on Mar 13, 2001 at 02:54 UTC

    I just realized that most strings won't have most characters in them so this can be sped up significantly via:

    my $count= 0; for( keys %{ { map {$_,1} unpack "C*", $str } } ){ my $c= pack "C", $_; $count += () = $str =~ /\Q$c\E/g; }
            - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://63996]
[LanX]: all combinations with same amount of left and right?
[Eily]: if you want to store in a structure with the coordinates as key, arrays might do, since the keys are going to be 0..n
[LanX]: (Pascale path)
[Eily]: paths like that
[Discipulus]: yes Eily++ (very keen) I want to integrate my project with a 17th experiments. I want to colorize in sequence all paths
[oiskuu]: Yeah, modifry the recursive func combinations() to return not the number, but the paths themselves.
[Eily]: Discipulus I'd do that by starting from the bottom node I think. That way it can inherit the paths from the two nodes above (and so on, recursively)
[LanX]: oh I meant fixed amount
[LanX]: every path must have l left and r right edges and l and r are fixed and l+r is the height
[LanX]: simple recursive function which goes left and right till l or r are exhausted

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-03-19 11:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.