20
2
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 so fewest bytes in each language wins!
No character is adjacent to a character that it was originally adjacent to. Does order not matter for adjacency? So input "abcd" cannot have "ab" anywhere, and cannot have "ba" anywhere either? – DrZ214 – 2017-06-09T07:03:19.867@DrZ214 that is correct – Skidsdev – 2017-06-09T08:00:25.217