Jump to content
cyfer65

Shuffle -> Unshuffle A String...?

Recommended Posts

I know there is a PHP function to shuffle a string.But is there a function to unshuffle that string..?If not, how could accomplish a shuffle -> unshuffle string function..?

Share this post


Link to post
Share on other sites

What exactly does an "unshuffle" function do?

Share this post


Link to post
Share on other sites

There's no way to know what the string was before it was shuffled, it could be any combination. You can save those pairs in a database if you want to look them up.

Share this post


Link to post
Share on other sites

How do we know what a string was before it was shuffled?You can, of course, order the string alphabetically using some array methods. But if you shuffle a string like "house" there's no way the computer will know what the word was before it was shuffled.

Share this post


Link to post
Share on other sites

Unshuffle this for me: "wisadfpovsavnkkslda"! (Hint: the answer is "vnkksldavsaisadwfpo".) :P (Technically, the point is that shuffle() is not bijective and thus not invertible, that is, there is no "unshuffle" function shuffle-1() such that shuffle-1(shuffle(x)) = x for all x. Of course, shuffle() isn't even deterministic.) If you mean, how can you arrange the characters of a string in alphabetical order, then you may want to try something involving sort(). ... as Ingolme said, and I didn't see :P.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...