in reply to counting instances of one array in another array

Sorry but searching thru an array "of all permutations of length n" doesnt make sense. If the tested string is shorter than n it will be a member by definition (modulo side criterias like repetition). If its just about counting use a hash like shown and a logical test.

Cheers Rolf

  • Comment on Re: counting instances of one array in another array

Replies are listed 'Best First'.
Re^2: counting instances of one array in another array
by jsmagnuson (Acolyte) on Feb 23, 2012 at 12:31 UTC

    Yep, I know that the patterns in @observed must be members of @perms. I want to get back the list of positions where the items in @observed occur in the ordered list of permutations in @perms. I am certain there is a better way to do this, and I've done a lot of searching on this site and others looking for better solutions, but I haven't found one yet. That's why I'm bringing this to the monks.

    Best wishes,

    jim

      Basically you want to give each pattern a specific id, right?

      So why don't you use a second hash that gives you the position in @perm for each pattern. Since @perm is fixed this hash is generated once and then available for the rest of the scripts runtime

      It's hard to believe that you really need the position in the array after switching to hashes.

      But well, lets continue this road...

      As long as the order isn't random but systematic you should be able to calculate this position.

      So plz search the internet or math books for algorithms generating all permutations by combination of two permutations named sigma and tau and reverse the process to get the index.

      This approach would limit time and space complexity considerably!

      Cheers Rolf