Created
January 9, 2017 19:40
-
-
Save mverteuil/a2b0642b794945dcec71bc192d3b0e64 to your computer and use it in GitHub Desktop.
Rangoli
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 rangoli(size): | |
width = size * 4 - 3 | |
chars = list(string.ascii_lowercase[:size]) | |
chars.reverse() | |
for row in range(1, size + 1): | |
chars_left = ''.join(chars[0:row]) | |
chars_right = ''.join(reversed(chars_left[:-1])) | |
print '-'.join(chars_left + chars_right).center(width, '-') | |
for row in reversed(range(1, size)): | |
chars_left = ''.join(chars[0:row]) | |
chars_right = ''.join(reversed(chars_left[:-1])) | |
print '-'.join(chars_left + chars_right).center(width, '-') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment