Created
December 1, 2013 19:31
-
-
Save alex-quiterio/7739775 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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