-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathrangoli.py
88 lines (73 loc) · 2.08 KB
/
rangoli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)
Different sizes of alphabet rangoli are shown below:
#size 3
----c----
--c-b-c--
c-b-a-b-c
--c-b-c--
----c----
#size 5
--------e--------
------e-d-e------
----e-d-c-d-e----
--e-d-c-b-c-d-e--
e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e--------
#size 10
------------------j------------------
----------------j-i-j----------------
--------------j-i-h-i-j--------------
------------j-i-h-g-h-i-j------------
----------j-i-h-g-f-g-h-i-j----------
--------j-i-h-g-f-e-f-g-h-i-j--------
------j-i-h-g-f-e-d-e-f-g-h-i-j------
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j
--j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
------j-i-h-g-f-e-d-e-f-g-h-i-j------
--------j-i-h-g-f-e-f-g-h-i-j--------
----------j-i-h-g-f-g-h-i-j----------
------------j-i-h-g-h-i-j------------
--------------j-i-h-i-j--------------
----------------j-i-j----------------
------------------j------------------
The center of the rangoli has the first alphabet letter a, and the boundary has the Nth alphabet letter (in alphabetical order).
"""
import string
from collections import defaultdict
d = defaultdict(list)
num = input()
alph = list(string.ascii_lowercase)
# print alph
# for i in xrange(num):
# print ((alph[num])+'-'*i).rjust(num*2,'-')+'#-'+('#-'*i).ljust(num*2,'-')
# for i in xrange(1,num):
# print (('#-'*(num-i-1)).rjust(num*2,'-')+'#-'+('#-'*(num-i-1)).ljust(num*2,'-'))
for i in range(1,(2*num-1)+1):
for j in range(1,(2*(2*num-1)-1)+1):
d[i].append('-')
k = (len(d)*2)//2
temp = (len(d)//2 )
for i in range(1,len(d)+1):
if i <= (len(d)+1)//2:
index = num
middle = (len(d[i])+1)//2
for j in range(k,k+4*i-3,2):
d[i][j-1] = alph[index-1]
if j >= middle:
index = index +1
else:
index = index -1
k = k-2
else:
d[i] = d[temp]
temp = temp -1
# print d
for i in range(1,len(d)+1):
print ''.join(d[i])