Alphabet Rangoli

Sort by

recency

|

1391 Discussions

|

  • + 0 comments

    For those who would be interested in my decision:

    def print_rangoli(size): max_letter_num = size + 96 dash = '-' new_list = [] for row in range(size): a = [chr(max_letter_num - num) for num in range(size - row)] new_list.append(a)

    for el in new_list[::-1]:
        content = dash.join(a for a in el)
        print(content.rjust((size * 2) - 1, dash) + content.rjust((size * 2) - 1, dash)[::-1][1:])
    for el1 in new_list[1:]:
        content = dash.join(a for a in el1)
        print(content.rjust((size * 2) - 1, dash) + content.rjust((size * 2) - 1, dash)[::-1][1:])
    return None
    
  • + 0 comments

    I really enjoyed how it challenges you to think about symmetry and spacing while working with characters from the alphabet. 11xplay ID

  • + 0 comments

    This here seems to be much easier with simple mirroring technique

    def print_rangoli(size): alpha = "abcdefghijklmnopqrstuvwxyz" width = size *4 -3 for i in range(size-1, -1, -1): left = alpha[size-1: i : -1] mid = alpha[i] right = alpha[i+1 :size ]

        final = '-'.join(left + mid + right)
        final1 = final.center(width, '-')
        print(final1)
    
    for i in range(1,size):
        mid = alpha[i]
        left = alpha[size-1: i : -1]
        right = alpha[i+1 :size ]
    
        final = '-'.join(left + mid + right)
        final1 = final.center(width, '-')
        print(final1)
    

    if name == 'main': n = int(input()) print_rangoli(n)

  • + 0 comments

    if you guies want a math, no list and pure logical then can reffer to this:

    def print_rangoli(size):
        # your code goes here
        p = 96 + size
        a = ( size - 1 ) * 2 + 1
        w = ( size - 1 ) * 4 + 1
        
        for i in range(a):
            ptrn = ""
            
            if i < size:
                itr = i
                v = p - i
            else:
                itr = a - i - 1
                v = p + i + 1 - a
            
            for j in range(itr):
                ptrn += chr(v-j+itr) + "-"
            
            ptrn += chr(v) + ptrn[::-1]
            print(ptrn.center(w,"-"))
    
    if __name__ == '__main__':
        n = int(input())
        print_rangoli(n)
    
  • + 0 comments

    Am I dumb?

    alph = list('abcdefghijklmnopqrstuvwxyz')
        w = ((size*2) - 1)*2 - 1
        
        print(alph[size-1].center(w, '-'))
        for i in range(1, size):
            print(("-".join(alph[size-1 : size-1-i : -1]) + '-' + "-".join(alph[size-1-i : size])).center(w, '-'))
            
        for i in range(size-2, 0, -1):
            print(("-".join(alph[size-1 : size-1-i : -1]) + '-' + "-".join(alph[size-1-i : size])).center(w, '-'))
        if size > 1:
            print(alph[size-1].center(w, '-'))