in reply to Re: Permutation with repetitions
in thread Permutation with repetitions

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.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^3: Permutation with repetitions
by umeboshi (Acolyte) on Jun 08, 2010 at 13:16 UTC
    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!
Re^3: Permutation with repetitions
by space_agent (Acolyte) on Jun 12, 2010 at 20:32 UTC
    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 :)