Skip to content

Commit 343ae9b

Browse files
Codechef --> Practise --> PPATTERN
1 parent 2118052 commit 343ae9b

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed

Codechef/Practise/PPATTERN.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'''
2+
3+
Consider the following 4×4 pattern:
4+
5+
1 2 4 7
6+
3 5 8 11
7+
6 9 12 14
8+
10 13 15 16
9+
You are given an integer N. Print the N×N pattern of the same kind (containing integers 1 through N2).
10+
11+
Input
12+
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
13+
The first and only line of each test case contains a single integer N.
14+
Output
15+
For each test case, print N lines; each of them should contain N space-separated integers.
16+
17+
Constraints
18+
1≤T≤10
19+
1≤N≤100
20+
Subtasks
21+
Subtask #1 (100 points): Original constraints
22+
23+
Example Input
24+
1
25+
4
26+
Example Output
27+
1 2 4 7
28+
3 5 8 11
29+
6 9 12 14
30+
10 13 15 16
31+
32+
'''
33+
34+
for _ in range(int(input())):
35+
n=int(input())
36+
a=[[None]*n for i in range(n)]
37+
k=1
38+
39+
for i in range(n):
40+
for j in range(i+1):
41+
a[j][i-j]=k
42+
k+=1
43+
44+
for i in range(1,n):
45+
for j in range(n-i):
46+
a[i+j][n-1-j]=k
47+
k+=1
48+
#display
49+
for i in range(n):
50+
for j in range(n):
51+
print(a[i][j],end=' ')
52+
print()

Codechef/Practise/Untitled.ipynb

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"n=b"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# Print Pattern \n",
15+
"- Problem Code: [PPATTERN](https://www.codechef.com/problems/PPATTERN)"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 37,
21+
"metadata": {},
22+
"outputs": [
23+
{
24+
"name": "stdin",
25+
"output_type": "stream",
26+
"text": [
27+
" 1\n",
28+
" 4\n"
29+
]
30+
},
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"1 2 4 7 \n",
36+
"3 5 8 11 \n",
37+
"6 9 12 14 \n",
38+
"10 13 15 16 \n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"for _ in range(int(input())):\n",
44+
" n=int(input())\n",
45+
" a=[[None]*n for i in range(n)]\n",
46+
" k=1\n",
47+
"\n",
48+
" for i in range(n):\n",
49+
" for j in range(i+1):\n",
50+
" a[j][i-j]=k\n",
51+
" k+=1\n",
52+
"\n",
53+
" for i in range(1,n):\n",
54+
" for j in range(n-i):\n",
55+
" a[i+j][n-1-j]=k\n",
56+
" k+=1\n",
57+
" #display\n",
58+
" for i in range(n):\n",
59+
" for j in range(n):\n",
60+
" print(a[i][j],end=' ')\n",
61+
" print()"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": 31,
67+
"metadata": {},
68+
"outputs": [
69+
{
70+
"data": {
71+
"text/plain": [
72+
"[[1, 2, 4, 7], [3, 5, 8, 11], [6, 9, 12, 14], [10, 13, 15, 16]]"
73+
]
74+
},
75+
"execution_count": 31,
76+
"metadata": {},
77+
"output_type": "execute_result"
78+
}
79+
],
80+
"source": [
81+
"a"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": 16,
87+
"metadata": {},
88+
"outputs": [
89+
{
90+
"data": {
91+
"text/plain": [
92+
"[[1, None, None, None, None],\n",
93+
" [None, None, None, None, None],\n",
94+
" [None, None, None, None, None],\n",
95+
" [None, None, None, None, None],\n",
96+
" [None, None, None, None, None]]"
97+
]
98+
},
99+
"execution_count": 16,
100+
"metadata": {},
101+
"output_type": "execute_result"
102+
}
103+
],
104+
"source": [
105+
"a[0][0]=1\n",
106+
"a"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": 17,
112+
"metadata": {},
113+
"outputs": [
114+
{
115+
"data": {
116+
"text/plain": [
117+
"[[1, None, None, None, None],\n",
118+
" [2, None, None, None, None],\n",
119+
" [None, None, None, None, None],\n",
120+
" [None, None, None, None, None],\n",
121+
" [None, None, None, None, None]]"
122+
]
123+
},
124+
"execution_count": 17,
125+
"metadata": {},
126+
"output_type": "execute_result"
127+
}
128+
],
129+
"source": [
130+
"a[1][0]=2\n",
131+
"a"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": null,
137+
"metadata": {},
138+
"outputs": [],
139+
"source": []
140+
}
141+
],
142+
"metadata": {
143+
"kernelspec": {
144+
"display_name": "Python 3",
145+
"language": "python",
146+
"name": "python3"
147+
},
148+
"language_info": {
149+
"codemirror_mode": {
150+
"name": "ipython",
151+
"version": 3
152+
},
153+
"file_extension": ".py",
154+
"mimetype": "text/x-python",
155+
"name": "python",
156+
"nbconvert_exporter": "python",
157+
"pygments_lexer": "ipython3",
158+
"version": "3.8.2"
159+
}
160+
},
161+
"nbformat": 4,
162+
"nbformat_minor": 4
163+
}

0 commit comments

Comments
 (0)