Created
May 27, 2016 18:56
-
-
Save emad-elsaid/42f1a9bca0a44d8a281c312b6f399995 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.join("\n") | |
puts diamond |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment