Skip to content

Instantly share code, notes, and snippets.

@banyan
Created December 27, 2009 15:37
Show Gist options
  • Select an option

  • Save banyan/264299 to your computer and use it in GitHub Desktop.

Select an option

Save banyan/264299 to your computer and use it in GitHub Desktop.
# [問題 6.2]
# * 文字列を,a ならば z,b ならば y,c ならば x のように,小文字も大文字もアルファベットの逆順の出現文字に置き換えるプログラムを作りなさい.
# http://www.aoni.waseda.jp/ichiji/2009/second-term/ruby-06-1.html
def reverse(s)
alphabet = ('a'..'z').to_a
if alphabet.index(s).nil?
alphabet[alphabet.size - alphabet.index(s.downcase)].upcase
else
alphabet[alphabet.size - alphabet.index(s)]
end
end
p reverse('R')
p reverse('A')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment