We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def print_rangoli(size):
# based on (abs(x) + abs(y) < size) against position of 'a' : (size-1, size*2 -2)
alpha='abcdefghijklmnopqrstuvwxyz'
for i in range(size*2 - 1) :
print (''.join([alpha[abs(i-size+1) + int(abs(j-size*2+2)/2)] \
if abs(j-size*2+2) % 2 ==0 and abs(i-size+1) + abs(j-size*2+2)/2 < size else '-' for j in range(size*4-3)]))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Alphabet Rangoli
You are viewing a single comment's thread. Return to all comments →
def print_rangoli(size): # based on (abs(x) + abs(y) < size) against position of 'a' : (size-1, size*2 -2) alpha='abcdefghijklmnopqrstuvwxyz'