6 Replies Latest reply on Jun 14, 2007 6:03 PM by kglad

# Array shuffle() - how to calculate minimum moves

It's easy to shuffle an array.
[h,e,l,p]
and reorder it to:
[h,l,p,e]

Ok, it's also easy to see that you only need one move to get the Array back to it's original order,
we just move the [e] two steps to the left.
But how to make a function that calculates this?

// usage example: deShuffle([h,l,p,e], "help");

Here is a practical example:
http://coldminer.com/nwf/example.html

Can anyone help me with this problem?
• ###### 1. Re: Array shuffle() - how to calculate minimum moves
"Easy to see"?

There may be a clever mathematical solution to this, but I don't know it.

Something like this I would probably get out some blocks and start with all the possible combinations for a 3 letter work and see how many steps it took.

Then I would do for a 4 letter word, and a five letter word. Hopefully by then a pattern would strike me.

Maybe somebody else will know off the top of their head.
• ###### 2. Re: Array shuffle() - how to calculate minimum moves
for words with duplicate letters this would require a bit of work. for words without duplicate letters calculating the minimum number of moves is straight-foreword.
• ###### 3. Re: Array shuffle() - how to calculate minimum moves
Yea... I was afraid that this would be a bit complicated.
Maybe I can pay for a script like this, any Idea how much I should expect to pay for a script like this?
• ###### 4. Re: Array shuffle() - how to calculate minimum moves
i'll do it for \$50.
• ###### 5. Re: Array shuffle() - how to calculate minimum moves
Great, I'll contact you as soon as I've sold the game concept.
(I develop education games for children)
• ###### 6. Re: Array shuffle() - how to calculate minimum moves
ok.