in reply to Re: counting instances of one array in another array
in thread counting instances of one array in another array

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

Replies are listed 'Best First'.
Re^3: counting instances of one array in another array
by jethro (Monsignor) on Feb 23, 2012 at 14:04 UTC

    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

Re^3: counting instances of one array in another array
by LanX (Saint) on Feb 23, 2012 at 13:22 UTC
    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