Created
September 13, 2016 03:19
-
-
Save akhy/78d60df2a4f767d0eb91224d214e95a0 to your computer and use it in GitHub Desktop.
My own solution to Kompas coding test http://bit.ly/2cnvywQ
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
#!/usr/bin/python | |
maxw=25 # largest width | |
minw=1 # smallest width | |
pad=1 # left-right padding per step | |
incr=pad*2 # | |
# assumptions | |
assert maxw >= minw + 2 # max width must be equals or greater than minw+2 | |
assert minw > 0 | |
assert maxw > 0 | |
assert maxw % 2 == 1 # max width must be an odd number | |
assert minw % 2 == 1 # min width must be an odd number | |
for linew in range(maxw, minw-1, -incr) + range(minw+incr, maxw+1, incr): | |
indent = (maxw - linew) / 2 | |
print (' ' * indent) + ('*' * linew) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment