Shuffle string of digits Challenge

You have been given a string of digits 0-9.1 Your task is to shuffle this string, but every index must have a different value than it did before the string was shuffled.

For example:

In : 287492
Out: 892247


If this is not possible, return false or something similar. (null, undefined, etc.)

In : 131
Out: false


There is no upper bound on the length of the string, but you can assume you have unlimited computation time.

Your function must pass the following tests:

shuffle('2')                   =&gt; false
shuffle('88')                  =&gt; false
shuffle('794588888')           =&gt; false
shuffle('344999')              =&gt; for example, '999434'
shuffle('172830560542976539')  =&gt; for example, '271038650425697395'



Shortest code wins, and good luck!





1 More specifically, the string would match /^[0-9]+$/.
K (ngn/k), 37 32 bytes

{$[|/x=r:x[,/|2 0N#&lt;x]@&lt;&lt;x;0;r]}


Try it online!

{ } function with argument x

$[ ; ; ] if-then-else

&lt;x "grade" - the sorting permutation for x

&lt;&lt;x "rankings" - the inverse of the sorting permutation

2 0N# split in two halves (or when length is odd - only approximately)

| swap the halves

,/ concatenate

x[ ] use as indices in x

..@&lt;&lt;x use &lt;&lt;x as indices in the previous result (a@b is alternative syntax for a[b])

r: assign to r - the potential result

x=r boolean list of which elements of x are equal to their counterparts in r

|/ or-reduction, i.e. "any?"