in reply to Permutation with repetitions

I'm not sure I've understood correctly what you want to do, but if you want to count matches of a certain characteristic in a given string, this snippet might help you:
my %matches; while ($str =~ /([abcd]{8,13})/g) { $matches{$1}++; } use Data::Dumper; print Dumper \%matches;
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Permutation with repetitions
by umeboshi (Acolyte) on Jun 07, 2010 at 10:01 UTC
    Hi,

    Thanks for replying. I don't think your code is what I am looking for. I'll try to explain again:

    For the sake of illustration let's say the size of the substring I am looking for is 3. Ideally, what I would like in the end is a list for all possible permutations with repetitions and a count how often they occur. For this example, the list would look something like that:

    aaa 0
    aab 2
    aac 1
    aad 0
    aba 2
    abb 0
    abc 1
    abd 0
    etc.
    How can this be achieved?
    Thanks
    Hadassa
      Ideally, what I would like in the end is a list for all possible permutations with repetitions and a count how often they occur.

      How often they occur... where? in which set/string/whatever?

      If you mean in the list of possible permutations, why are some of them 0?

      Perl 6 - links to (nearly) everything that is Perl 6.
        I am looking in a long string of the sort:

        aaaabdbbdaccdacdaaabdcd...

        and thus want to know the number of occurrences of any of the substrings of size 3 (as in the example). Sure, I could leave out the ones which are zero, don't need them. But I thought that I will have to loop over all possible substrings of size 3 anyway and count their occurrences.
        Thanks,
        Hadassa