4 added 22 characters in body

# Stax, 23 21 bytes

å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö


Run and debug online!

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!

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


# Stax, 23 21 bytes

å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö


Run and debug online!

Thanks for @recursive for saving 2 bytes.

Takes a very long time to run. A more reasonable/feasible version is

Ç≡╨áiS║çdèû.#-Gî☺└╨◙σφ+


Run and debug online!

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


# Stax, 23 21 bytes

å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö


Run and debug online!

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!

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

3 added 108 characters in body

# Stax, 2323 21 bytes

₧¡U=δà╗▌âÜ╚g$¬g⌐☺Ñ╩⌂╪╧↕å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö  Thanks for @recursive for saving 2 bytes. Takes a very long time to run. A more reasonable/feasible version is üzñ7_PZ7ƒTPNL&┘↨\:ø╧FÇ≡╨áiS║çdèû.î*•Ç#-Gî☺└╨◙σφ+  ## Explanation Uses the unpacked version to explain. w|Nc_:=n{ch+2B}X!yx!|*=nGyG|*{E-!f+}ch+2B w Loop theanything wholebefore program} while condition is satisfied |N Next permutation (starting from the input) c_:= Index where the current array has the same element as the input (*) n{ch+2B}X! }ch+2B FindDefine a block that finds all contiguous pairs in current string, including the pair [last element, first element] nG yx! 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 { f Only keep pairs E-! 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  # Stax, 23bytes ₧¡U=δà╗▌âÜ╚g$¬g⌐☺Ñ╩⌂╪╧↕


Run and debug online!

Takes a very long time to run. A more reasonable/feasible version is

üzñ7_PZ7ƒTPNL&┘↨\:ø╧F.î*•Ç


Run and debug online!

## Explanation

Uses the unpacked version to explain.

w|Nc_:=n{ch+2B}X!yx!|*{E-!f+
w                               Loop the whole program while condition is satisfied
|N                             Next permutation (starting from the input)
c_:=                         Index where the current array has the same element as the input (*)
n{ch+2B}X!               Find all contiguous pairs in current string, including the pair [last element, first element]
yx!            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


# Stax, 23 21 bytes

å╘┤‼¬½P¥ë└w↕⌐î◘E{╟u!Ö


Run and debug online!

Thanks for @recursive for saving 2 bytes.

Takes a very long time to run. A more reasonable/feasible version is

Ç≡╨áiS║çdèû.#-Gî☺└╨◙σφ+


Run and debug online!

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

2 added 2 characters in body

# Stax, 23 bytes

₧¡U=δà╗▌âÜ╚g$¬g⌐☺Ñ╩⌂╪╧↕  Run and debug online! Takes a very long time to run. A more reasonable/feasible version is üzñ7_PZ7ƒTPNL&┘↨\:ø╧F.î*•Ç  Run and debug online! ## Explanation Uses the unpacked version to explain. w|Nc_:=n{ch+2B}X!yx!|*{E-!f+ w Loop the whole program while condition is satisfied |N Next permutation (starting from the input) c_:= Index where the current array has the same indexelement as the input (*) n{ch+2B}X! Find all contiguous pairs in current string, including the pair [last element, first element] yx! 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  # Stax, 23 bytes ₧¡U=δà╗▌âÜ╚g$¬g⌐☺Ñ╩⌂╪╧↕


Run and debug online!

Takes a very long time to run. A more reasonable/feasible version is

üzñ7_PZ7ƒTPNL&┘↨\:ø╧F.î*•Ç


Run and debug online!

## Explanation

Uses the unpacked version to explain.

w|Nc_:=n{ch+2B}X!yx!|*{E-!f+
w                               Loop the whole program while condition is satisfied
|N                             Next permutation (starting from the input)
c_:=                         Index where the current array has the same index as the input (*)
n{ch+2B}X!               Find all contiguous pairs in current string, including the pair [last element, first element]
yx!            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


# Stax, 23 bytes

₧¡U=δà╗▌âÜ╚g\$¬g⌐☺Ñ╩⌂╪╧↕


Run and debug online!

Takes a very long time to run. A more reasonable/feasible version is

üzñ7_PZ7ƒTPNL&┘↨\:ø╧F.î*•Ç


Run and debug online!

## Explanation

Uses the unpacked version to explain.

w|Nc_:=n{ch+2B}X!yx!|*{E-!f+
w                               Loop the whole program while condition is satisfied
|N                             Next permutation (starting from the input)
c_:=                         Index where the current array has the same element as the input (*)
n{ch+2B}X!               Find all contiguous pairs in current string, including the pair [last element, first element]
yx!            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

1