Alphabet Rangoli

Sort by

recency

|

1364 Discussions

|

  • + 0 comments

    I threw in some math to reflect the structure of the diamond. Could probably consolidate parts of it, but I like how it shows where each part comes from.

    def print_rangoli(size):
        alphabet = "abcdefghijklmnopqrstuvwxyz"
        fill = "-"
        width = 2 * (size - 1)
    
    
        def build_line(index):
            l_text = "".join([alphabet[size - j - 1] + fill for j in range(index)]).rjust(
                width, fill
            )
            c_text = alphabet[size - index - 1]
            r_text = "".join([fill + alphabet[size - j] for j in range(index, 0, -1)]).ljust(
                width, fill
            )
            return l_text + c_text + r_text
    
        i = 0
        while i < 2 * size - 1:
            line_val = -abs(i - (size - 1)) + size - 1
            text = build_line(line_val)
            print(text)
            i += 1
    
  • + 0 comments

    def print_rangoli(n):

    w = (n*2-1)*2 - 1
    al = "abcdefghijklmnopqrstuvwxyz"
    
    for i in range(n-1,-1,-1):
    
        a=f"{al[i]}"
        for x in range(i+1,n):
            a= f"{al[x]}-" +a+ f"-{al[x]}"
        print(a.center(w,"-"))
    
    for i in range(1,n):
        a=f"{al[i]}"
        for x in range(i+1,n):
            a= f"{al[x]}-" +a+ f"-{al[x]}"
        print(a.center(w,"-"))
    

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

  • + 0 comments

    entre vouz

    def print_rangoli(n):

    # your code goes here
    z = "abcdefghijklmnopqrstuvwxyz"
    #join till nth string
    b = "".join(z[:n])
    #reverse it 1st half 
    b = b[::-1]
    #c holds
    # (i)loop for i till n
    # (ii)all items of b till i
    # (iii)all items including i and reversed
    c = [b[:i]+b[:i+1][::-1] for i in range(n)]
    # from list c it joins all the items with dash
    # also it centers the item with n*4-3 width and - for spaces 
    d=["-".join(i).center(n*4-3,"-") for i in c]
    #top half
    #prints the items of d after a new line
    print("\n".join(d))
    #bottom half
    #prints the items of d in reverse after new line
    #the middle line is ignored ... [1:]
    print("\n".join(d[::-1][1:]))
    

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

  • + 0 comments

    def print_rangoli(size): # your code goes here width = (size * 4) -3 alphabet = "abcdefghijklmnopqrstuvwxyz" substr = alphabet[0:size][::-1] #reversed substring eg. edcba

    lines_above = ["-".join(substr[0:i+1] + substr[0:i+1][:-1][::-1]).center(width, '-') for i in range(size)]
    lines_below = [*reversed(lines_above[:-1])]
    
    rangoli = lines_above + lines_below
    
    print(*rangoli, sep="\n")
    
  • + 0 comments

    What a creative task! Alphabet rangolis are such a beautiful way to blend art and mathematics, and it's amazing how the patterns evolve based on the given size. Each design, from smaller to larger sizes, reflects the symmetry and balance of the letters in the alphabet, Ekbet71