Alphabet Rangoli

  • + 2 comments

    It's simple. When n=3, the patten will be printed as below.

    ----c----
    --c-b-c--
    c-b-a-b-c
    --c-b-c--
    ----c----

    If you observe, there are 9 characters on each line. When you consider c-b-a-b-c (the line in the center), the number of characters is 1{for a}+2*(n-1){for b,c}+(2n-2){add the previous 2 and subtract 1 from it, because the number of '-' is one less than the number of characters in the line}. That's how we arrived at 4n-3. Similarly when n=4, we'll have 13 characters and when n=5, we'll have 17. Hope this helped!