Go - convert the string to a slice of runes, swap the runes in the slice via some bit manipulation, then convert the slice back to string and return it.
Remember, to swap the values of two integers a and b...
We split the string into a slice of ordered rune-index pairs, reverse the slice by sorting based on the indices, then get the resulting string from the reordered slice. It's pretty inefficient to begin with, and choosing bubblesort as our sorting algorithm gets us some O(N^2) fun.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Go - convert the string to a slice of runes, swap the runes in the slice via some bit manipulation, then convert the slice back to string and return it.
Remember, to swap the values of two integers a and b...
a = a XOR b
b = a XOR b
a = a XOR b
Update: it occurred to me that the solution above may be odd, but it's not that inefficient. We can do better. So... take 2:
We split the string into a slice of ordered rune-index pairs, reverse the slice by sorting based on the indices, then get the resulting string from the reordered slice. It's pretty inefficient to begin with, and choosing bubblesort as our sorting algorithm gets us some O(N^2) fun.