Shuffle string of digits

K (ngn/k), 37 32 bytes

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

Try it online!

{ } function with argument x

$[ ; ; ] if-then-else

<x "grade" - the sorting permutation for x

<<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

..@<<x use <<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?"

05AB1E, 7 bytes

Like the Pyth answer, outputs all possible shuffled strings or digits.


Try it online!


œ       Permutations of the input
 ʒ      Filter such that:
  ø        Zipping with the original input
   €Ë      And comparing at corresponding indices
     à_    are all unequal.

Pyth, 9 bytes


Try it online!

Outputs all possible strings that meet the criteria given in the question. This results in an empty list for the false cases.