[Question]
  [
Given a string as input, output one or more variants of the string such that:
* No character is in it's original position
* No character is adjacent to a character that it was originally adjacent to
You can assume this will always be possible for the given string, and will only contain single case alphabetical characters (`[a-z]` or `[A-Z]` if you prefer)
Note that duplicates of the same character are not considered unique.
For example, given the input `programming`, the output cannot contain an `m` at the 7th **or** 8th character, and cannot contain a `g` at the 4th **or** 11th character (1 indexed)
## Example:
Take the string `abcdef`
The following would be a valid output: `daecfb`
However the following would be invalid: `fdbcae` as in this example `c` and `b` are still adjacent.
Adjacency also wraps, meaning you could not do `fdbeca` as `f` and `a` are still adjacent.
## Testcases:
Note these are not the **only** valid outputs for the given inputs
Written as `input -> output`:
```
helowi -> ioewhl
mayube -> euabmy
stephens -> nhseespt
aabcdeffghij -> dbfhjfigaeca
```
## Scoring:
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so fewest bytes **in each language** wins!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~24~~ 23 bytes
```
ẋ2ṡ2Ṣ€
Ç³Ç¤œ&¬ɓ³=Sȯ
ẊÇ¿
```
[Try it online!](https://tio.run/##y0rNyan8///hrm6jhzsXAvGiR01ruA63H9oMxEuOTlY7tObk5EObbYNPrOd6uKsLKLj/////xSWpBRmpecVf8/J1kxOTM1IB "Jelly – Try It Online")
Extremely long by virtue of my being awful at Jelly, but it finally works, at least... still in the process of golfing.
```
link that generates a list of sorted adjacent pairs:
ẋ2            duplicate argument ("abc" -> "abcabc")
  ṡ2          slices of 2 (-> "ab","bc","ca","ab","bc")
    Ṣ€        sort each
link that tests for invalid permutations:
Ç             get sorted adjacent pairs of argument
 ³Ç¤          do the same for the original input
    œ&        set intersection, then...
      ¬       ...inverse; i.e. do they have no elements in common
       ɓ   ȯ  logical OR the result of that with...
        ³=    elementwise equality with original input, and...
          S   ...sum; i.e. are some characters in the same position
main link:
Ẋ             shuffle the input list
  ¿           while
 Ç            the result of the previous link is truthy
```
[Answer]
# [Python 2](https://docs.python.org/2/), 185 bytes
```
from itertools import*
x=input()
g=lambda m:set(zip(m*2,(m*2)[1:]))
for l in permutations(x):
 if not((g(l)|g(l[::-1]))&(g(x)|g(x[::-1]))or any(a==b for a,b in zip(x,l))):print`l`[2::5]
```
[Try it online!](https://tio.run/##NY29CsMgFEZ3n@JOjbekQwJdhDxJCESpSQX/MDdgSt/d6tDlDAe@88WL3sGPpWwpODCkE4VgDzAuhkR3lifj40kc2T5Z6dRLghOHJv4xkbv72DfgPIgFkW0hgQXjIerkTpJkgj94RsHAbOADcb5zi9@KWYjHUDe3anIz@W9qQ/qLy2lS0IKyVy3Z/nJvEVHEZDytdp1HIZ5LKZ2T16l09wM "Python 2 – Try It Online")  
Prints all valid strings
[Answer]
# PHP>=7.1, 147 Bytes
```
for($a=$argn,$r="^$a[-1].*$a[0]$",$k=0;$v=$a[$k];)$r.="|^.{{$k}}$v|$v".($l=$a[$k++-1])."|$l$v";for(;preg_match("#$r#",$s=str_shuffle($a)););echo$s;
```
[PHP Sandbox Online](http://sandbox.onlinephpfunctions.com/code/ff9639358c96755feecb1e5016fbf58b726a67a6)
# PHP>=7.1, 184 Bytes
Use the levenshtein distance instead of a Regex way
```
for($a=$argn;$v=$a[$k];$r[]=$l.$v)$r[]=$v.($l=$a[$k++-1]);for(;!$t&&$s=str_shuffle($a);)for($t=1,$i=0;$v=$s[$i];$t*=$v!=$a[$i++])foreach($r as$x)$t*=levenshtein($x,$s[$i-1].$v);echo$s;
```
[PHP Sandbox Online](http://sandbox.onlinephpfunctions.com/code/82c1d3d19dd32cbf4eaef6073b13adc428be5285)
# [PHP](https://php.net/), 217 bytes
Version under 7.1
```
for($l=strlen($a=$argn),$r=$a[$k=0].$a[$l-1]."|".$a[$l-1]."$a[0]|^{$a[$l-1]}.*$a[0]$";$v=$a[$k];!$k?:$r.="|$v".$a[$k-1],++$k<$l?$r.="|$v".$a[$k]:0)$r.="|^.{{$k}}$v";for(;preg_match("#$r#",$s=str_shuffle($a)););echo$s;
```
[Try it online!](https://tio.run/##XY9NboMwEIX3vUWHt8ANscg2jsVBGidCyMSVXWOZNFkAx86amqBKVXbfvB/pTTBhPlTBhDfU8eIlGe26@xeJue1iDif7a3Ta56jlM8AKxESfsLJUfAG33SlOI/07EpVqPA1/ysQ/nhJI4La2lXiHrfaIXNKI29q2KVtsNrAHuOrFUvuSrdKJDwPsNCVLLCNFiPpy/q6vjckpQ8yoQL/sPvfmp22dTuMZE0zoxnToxZwtQEd/9Ijp0Yfvtk3dGP0L "PHP – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 21 bytes
```
p.jP;?z≠ᵐ&j¬{s₂p~s}P∧
```
[Try it online!](https://tio.run/##ATYAyf9icmFjaHlsb2cy//9wLmpQOz964omg4bWQJmrCrHtz4oKCcH5zfVDiiKf//yJhc2RmZ2gi/1o "Brachylog – Try It Online")
## Explanation
I really would have wanted for `p.;?z≠ᵐ&j¬{s₂p~s~j}` to work for 2 bytes less, but it seems `~j` is not smart enough...
```
p.jP;?z≠ᵐ&j¬{s₂p~s}P∧  Input is a string, say ? = "asdfgha"
p                      Take a permutation of ?, say "sfagadh".
 .                     It is the output.
  j                    Concatenate it to itself: "sfagadhsfagadh"
   P                   Call that string P.
    ;?                 Pair P with the input: ["sfagadhsfagadh","asdfgha"]
      z                Zip, repeating elements of the longer string:
                        [["s","a"],["f","s"],["a","d"],...,["a","g"],["d","h"],["h","a"]]
       ≠ᵐ              Each pair must have different elements.
         &             Start new predicate
          j            Concatenate ? to itself: "asdfghaasdfgha"
           ¬{     }    The following cannot be satisfied:
             s₂        Take a substring of length 2
               p       and permute it.
                ~s     It is a substring of
                   P   P.
                    ∧  Do not unify P with the output.
```
[Answer]
# PHP 7.1, ~~136~~ 131 bytes
inspired by [Jörg´s solution](https://codegolf.stackexchange.com/a/125350/55735):
```
for($a=$argn;$c=$a[$k];)$r.="|$c".($d=$a[$k-1])."|$d$c|^.{".+$k++."}$c";while(preg_match("#$a$r#",($s=str_shuffle($a)).$s));echo$s;
```
Run as pipe with `-r` or [test it online](http://sandbox.onlinephpfunctions.com/code/88d76bcb156a2ddeb88effca91b04f2958a04eae). (Make sure that PHP version 7.1 or above is selected)
Requires PHP 7.1; add 14 bytes for older PHP: Replace `$k-1` with `($k?:strlen($a))-1`;  
(two more bytes for PHP<5.3: `$k?$k-1:strlen($a)-1`)
**breakdown**
```
# A: loop through input to collect sub-expressions
for($a=$argn;$c=$a[$k];)
    $r.="|$c".($d=$a[$k-1])     # 1. pair of characters
        ."|$d$c"                # 2. reversed pair
        ."|^.{".+$k++."}$c";    # 3. $c is at k-th position
# B: shuffle input until regex does not match the result
while(preg_match("#$a$r#",($s=str_shuffle($a)).$s));    # (input as dummy sub-expression)
# C: print result
echo$s;
```
[Answer]
# PHP 7.1, ~~187 185 172 178~~ 143 bytes
```
do for($r=str_shuffle($s=$argn),$p=$i=0;$c=$s[$i];$p+=($c==$z)+preg_match("#$a|$b#",$s.$s))$b=strrev($a=$r[$i-1].$z=$r[$i++]);while($p);echo$r;
```
Run as pipe with `-r` or [test it online](http://sandbox.onlinephpfunctions.com/code/a136a8d3393176a2361271a3126b9eefadf9959e). (Make sure that PHP version 7.1.0 or above is selected!)
**breakdown**
```
do
    for($r=str_shuffle($s=$argn),   # 2. shuffle input
        $p=$i=0;$c=$s[$i];          # 3. loop through input
        $p+=($c==$z)                        # 2. set $p if char is at old position
            +preg_match("#$a|$b#",$s.$s)    #    or if adjacency occurs in input
    )
        $b=strrev($a=$r[$i-1].$z=$r[$i++]); # 1. concat current with previous character
while($p);                          # 1. loop until $p is falsy
echo$r;                             # 4. print
```
[Answer]
# Ruby, ~~110~~ ~~97~~ 102 bytes
```
->s{x=s.chars
t=s*2
x.shuffle!while s.size.times.any?{|i|a,b=(x*2)[i,2];a==s[i]||t[a+b]||t[b+a]}
x*''}
```
[Try it online!](https://tio.run/##JcvPDoIgHADgu09BXixUpvR/jXoQxgEcDDaz5k8XJj52Z9rq9J2@flRTNCyWV5g9A9JY2UMyMMA08QTsaEyrVy/rWo2AgHtrMri7BiK76TYHF2Sh2NpjuuGuoOIiGQPuRAgDl7n6qXIplsTjLFtiXf07mtETGZ5WNd3u9ofj6ZwKtMRP9ygb2Vj9BQ "Ruby – Try It Online")
[Answer]
# JavaScript 6, 116 Bytes
```
f=x=>(h=[...x].sort(_=>Math.random(z=0)-.5)).some(y=>y==x[z]||(x+x).match(y+(q=h[++z]||h[0])+'|'+q+y))?f(x):h.join``
```
```
f=x=>(h=[...x].sort(_=>Math.random(z=0)-.5)).some(y=>y==x[z]||(x+x).match(y+(q=h[++z]||h[0])+'|'+q+y))?f(x):h.join``
console.log (f('abcdef'));
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~23~~ 21 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö
```
[Run and debug online!](https://staxlang.xyz/#p=86d4b413aaab509d89c07712a98c08457bc7752199&i=helowi%0Amayube%0Astephens%0Aaabcdeffghij&a=1&m=2)
Thanks for @recursive for saving 2 bytes.
Takes a very long time to run. A more reasonable/feasible version is (just 2 bytes longer)
```
Ç≡╨áiS║çdèû.#-Gî☺└╨◙σφ+
```
[Run and debug online!](https://staxlang.xyz/#p=80f0d0a06953ba87648a962e232d478c01c0d00ae5ed2b&i=helowi%0Amayube%0Astephens%0Aaabcdeffghij&a=1&m=2)
## Explanation
Uses the unpacked version to explain.
```
w|Nc_:=nGyG|*{E-!f+}ch+2B
w                            Loop anything before `}` while
 |N                          Next permutation (starting from the input)
   c_:=                      Index where the current array has the same element as the input (*)
                   }ch+2B    Define a block that finds all contiguous pairs in current string, including the pair `[last element, first element]`
       nG                    Apply the defined block to current string                         
         yG                  Do the same for the input
           |*                Outer product, contains pairs (which themselves are pairs) constructed from the last two array.
             {   f           Only keep pairs
              E-!            whose two elements have the same set of characters
                  +          Prepend the array at step (*).
                             This is used as the condition for the while loop
```
]