Skip to content

Instantly share code, notes, and snippets.

@alex-quiterio
Created December 1, 2013 19:31
Show Gist options
  • Save alex-quiterio/7739775 to your computer and use it in GitHub Desktop.
Save alex-quiterio/7739775 to your computer and use it in GitHub Desktop.
def swap_string(string)
i = 0
j = string.length - 1
while i < j do
string[i] = (string[i].ord ^ string[j].ord).chr
string[j] = (string[i].ord ^ string[j].ord).chr
string[i] = (string[i].ord ^ string[j].ord).chr
i+=1
j-=1
end
puts string
end
swap_string("HELLO WORLD")
swap_string("THIS IS GREAT")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment