Last active
May 27, 2016 18:58
-
-
Save emad-elsaid/98c7f89916056ec7bab70ee99d5ff091 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
end_char = ARGV.first | |
characters = ('A'..end_char).to_a + ('A'...end_char).to_a.reverse | |
max_level = end_char.ord - 'A'.ord | |
diamond = characters.map do |char| | |
current_level = char.ord - 'A'.ord | |
before_spaces = max_level - current_level | |
if char == 'A' | |
' ' * before_spaces + char | |
else | |
inner_spaces = (current_level - 1) * 2 + 1 | |
' ' * before_spaces + char + ' ' * inner_spaces + char | |
end | |
end | |
puts diamond |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment