in reply to Permutation with repetitions

Thanks everyone for their comments. They were very helpful

An additional complexity to the problem is that I have some characters, say "x", in the string which are not to be counted, i.e.

aaaabccbaxxxcbddadcc...

So if n=3 as in the example any substring of size 3 that includes an x needs to be ignored and not counted.

Any ideas on that?
Thanks again!

Replies are listed 'Best First'.
Re^2: Permutation with repetitions
by BrowserUk (Patriarch) on Jun 08, 2010 at 12:54 UTC

    Presumably, you don't want to count substrings that would be formed by the removal of the Xs?

    Also, you mentioned earlier having all the permutations, including those with zero occurances, in the results hash. The problem with that is that by the time you get to n=13, you'd have 67 million entries in the hash, most of which would be 0.

    Anyway, this might be of some use:

    $s = 'aaaabccbaxxxcbddadcc';; ++$h{ $1 } while $s =~ m[(?=([abcd]{3})).]g;; pp \%h;; { aaa => 2, aab => 1, abc => 1, adc => 1, bcc => 1, bdd => 1, cba => 1, cbd => 1, ccb => 1, dad => 1, dcc => 1, dda => 1, }

    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.
      Yes, forgot to mention that of course I will not store the one which have count zero.

      Your answer was perfect! I guess I will have to catch up on some regular expressions!


      Great!
      Thanks a lot!
      Very interesting solution. May I ask why you put two ;; at the end of each line and what pp in pp \%h" does ?

        I refer my honourable friend to my previous answer no: 804630 :)

Re^2: Permutation with repetitions
by moritz (Cardinal) on Jun 08, 2010 at 12:33 UTC
    next if $substr =~ /x/;
    Perl 6 - links to (nearly) everything that is Perl 6.