Created
December 27, 2009 15:37
-
-
Save banyan/264299 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # [問題 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