From 30bf83d5b2379f6482ee2ac9c37e66df4000f4fd Mon Sep 17 00:00:00 2001 From: Deepanshu Jain Date: Sun, 7 Oct 2018 18:13:28 +0530 Subject: [PATCH 1/2] pattern problems added n cpp --- Pattern-Problems/.DS_Store | Bin 0 -> 6148 bytes Pattern-Problems/README.md | 367 +++++++++++++++++++++++++++++ Pattern-Problems/cpp/pattern01.cpp | 19 ++ Pattern-Problems/cpp/pattern02.cpp | 21 ++ Pattern-Problems/cpp/pattern03.cpp | 22 ++ Pattern-Problems/cpp/pattern04.cpp | 15 ++ Pattern-Problems/cpp/pattern05.cpp | 15 ++ Pattern-Problems/cpp/pattern06.cpp | 20 ++ Pattern-Problems/cpp/pattern07.cpp | 24 ++ Pattern-Problems/cpp/pattern08.cpp | 22 ++ Pattern-Problems/cpp/pattern09.cpp | 21 ++ Pattern-Problems/cpp/pattern10.cpp | 23 ++ Pattern-Problems/cpp/pattern11.cpp | 17 ++ Pattern-Problems/cpp/pattern12.cpp | 15 ++ Pattern-Problems/cpp/pattern13.cpp | 17 ++ Pattern-Problems/cpp/pattern14.cpp | 28 +++ Pattern-Problems/cpp/pattern15.cpp | 27 +++ Pattern-Problems/cpp/pattern16.cpp | 22 ++ Pattern-Problems/cpp/pattern17.cpp | 25 ++ Pattern-Problems/cpp/pattern18.cpp | 32 +++ Pattern-Problems/cpp/pattern19.cpp | 43 ++++ Pattern-Problems/cpp/pattern20.cpp | 40 ++++ Pattern-Problems/cpp/pattern21.cpp | 28 +++ Pattern-Problems/cpp/pattern22.cpp | 38 +++ Pattern-Problems/cpp/pattern23.cpp | 20 ++ Pattern-Problems/cpp/pattern24.cpp | 21 ++ Pattern-Problems/cpp/pattern25.cpp | 20 ++ Pattern-Problems/cpp/pattern26.cpp | 26 ++ Pattern-Problems/cpp/pattern27.cpp | 20 ++ Pattern-Problems/cpp/pattern28.cpp | 29 +++ Pattern-Problems/cpp/pattern29.cpp | 25 ++ Pattern-Problems/cpp/pattern30.cpp | 57 +++++ Pattern-Problems/cpp/pattern31.cpp | 40 ++++ Pattern-Problems/cpp/pattern32.cpp | 23 ++ Pattern-Problems/cpp/pattern33.cpp | 37 +++ contributors.md | 3 +- 36 files changed, 1221 insertions(+), 1 deletion(-) create mode 100644 Pattern-Problems/.DS_Store create mode 100644 Pattern-Problems/README.md create mode 100644 Pattern-Problems/cpp/pattern01.cpp create mode 100644 Pattern-Problems/cpp/pattern02.cpp create mode 100644 Pattern-Problems/cpp/pattern03.cpp create mode 100644 Pattern-Problems/cpp/pattern04.cpp create mode 100644 Pattern-Problems/cpp/pattern05.cpp create mode 100644 Pattern-Problems/cpp/pattern06.cpp create mode 100644 Pattern-Problems/cpp/pattern07.cpp create mode 100644 Pattern-Problems/cpp/pattern08.cpp create mode 100644 Pattern-Problems/cpp/pattern09.cpp create mode 100644 Pattern-Problems/cpp/pattern10.cpp create mode 100644 Pattern-Problems/cpp/pattern11.cpp create mode 100644 Pattern-Problems/cpp/pattern12.cpp create mode 100644 Pattern-Problems/cpp/pattern13.cpp create mode 100644 Pattern-Problems/cpp/pattern14.cpp create mode 100644 Pattern-Problems/cpp/pattern15.cpp create mode 100644 Pattern-Problems/cpp/pattern16.cpp create mode 100644 Pattern-Problems/cpp/pattern17.cpp create mode 100644 Pattern-Problems/cpp/pattern18.cpp create mode 100644 Pattern-Problems/cpp/pattern19.cpp create mode 100644 Pattern-Problems/cpp/pattern20.cpp create mode 100644 Pattern-Problems/cpp/pattern21.cpp create mode 100644 Pattern-Problems/cpp/pattern22.cpp create mode 100644 Pattern-Problems/cpp/pattern23.cpp create mode 100644 Pattern-Problems/cpp/pattern24.cpp create mode 100644 Pattern-Problems/cpp/pattern25.cpp create mode 100644 Pattern-Problems/cpp/pattern26.cpp create mode 100644 Pattern-Problems/cpp/pattern27.cpp create mode 100644 Pattern-Problems/cpp/pattern28.cpp create mode 100644 Pattern-Problems/cpp/pattern29.cpp create mode 100644 Pattern-Problems/cpp/pattern30.cpp create mode 100644 Pattern-Problems/cpp/pattern31.cpp create mode 100644 Pattern-Problems/cpp/pattern32.cpp create mode 100644 Pattern-Problems/cpp/pattern33.cpp diff --git a/Pattern-Problems/.DS_Store b/Pattern-Problems/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..20a8cdc98a4b1f5d1ced8d31700d2cf530031948 GIT binary patch literal 6148 zcmeH~Jx;?w5QX1DkOC-DIw)OIMVNm?VJ^ zm;>g(-*Z6T-7P#~fH_uJe}CnZaK$|M($HJ)VZpIW{+{rP7aSrbIbrW&?adeRqm?|W zC*58vc^o0%TFH|L`PoXI)|2Ycd!s{V5mFp#CeQ0hb*P!Vh>+q?GkF;y#i1rL4fla^Lm-;`7um8)C?U@7Sz`t_9b@Kas$VUpbweoOM tYZK-JQ$ofSUKL>z%CT-pDc)yl@K_=n)GTP>l|2mmBcL`|V-EbP1K*7&$%Fs^ literal 0 HcmV?d00001 diff --git a/Pattern-Problems/README.md b/Pattern-Problems/README.md new file mode 100644 index 0000000..b016d4e --- /dev/null +++ b/Pattern-Problems/README.md @@ -0,0 +1,367 @@ +# Pattern-Problems + +#### Pattern 1: + +``` +N = 4 + 1 + 1 1 + 1 1 1 + 1 1 1 1 +``` + +#### Pattern 2: + +``` +N = 4 + 1 + 2 3 + 4 5 6 + 7 8 9 10 +``` +#### Pattern 3: + +``` +N = 4 + 1 + 2 3 + 3 4 5 + 4 5 6 7 +``` + +#### Pattern 4: + +``` +N = 4 + 1 1 1 1 + 1 1 1 + 1 1 + 1 +``` + +#### Pattern 5: + +``` +N = 4 + 1 2 3 4 + 1 2 3 + 1 2 + 1 +``` + +#### Pattern 6: + +``` +N = 4 + 1 + 1 1 + 1 1 1 + 1 1 1 1 +``` + +#### Pattern 7: + +``` +N = 4 + 1 + 2 3 + 4 5 6 + 7 8 9 10 +``` + +#### Pattern 8: + +``` +N = 4 + 1 + 2 3 + 3 4 5 + 4 5 6 7 +``` + +#### Pattern 9: + +``` +N = 4 + 1 1 1 1 + 1 1 1 + 1 1 + 1 +``` + +#### Pattern 10: + +``` +N = 4 + 1 2 3 4 + 1 2 3 + 1 2 + 1 +``` + +#### Pattern 11: + +``` +N = 4 + A + B B + C C C + D D D D +``` + +#### Pattern 12: + +``` +N = 4 + 1 1 1 1 + 0 0 0 + 1 1 + 0 +``` + +#### Pattern 13: + +``` +N = 4 + D + C D + B C D + A B C D +``` + +#### Pattern 14: + +``` +N = 4 + 1 + 3 2 + 4 5 6 + 10 9 8 7 +``` + +#### Pattern 15: + +``` +N = 4 + A B C D D C B A + A B C C B A + A B B A + A A +``` + +#### Pattern 16: + +``` +N = 4 + 4 4 4 4 + 3 4 4 4 + 2 3 4 4 + 1 2 3 4 +``` + +#### Pattern 17: + +``` +N = 4 + 0 + 1 0 1 + 2 1 0 1 2 + 3 2 1 0 1 2 3 + 4 3 2 1 0 1 2 3 4 +``` + +#### Pattern 18: + +``` +N = 5 (N is always odd) + * + * * + * * * + * * + * +``` + +#### Pattern 19: + +``` +N = 5 (N is always odd) + * + * * * + * * * * * + * * * + * +``` + + +#### Pattern 20: + +``` +N = 5 (N is always odd) + 1 + 1 2 3 + 1 2 3 4 5 + 1 2 3 + 1 +``` + + +#### Pattern 21: + +``` +N = 4 + 1 + 2 3 2 + 3 4 5 4 3 + 4 5 6 7 6 5 4 +``` + + +#### Pattern 22: + +``` +N = 5 #####(N is always odd) + * + * * + * * * + * * + * +``` + + +#### Pattern 23: + +``` +N = 5 + 1 + 1 1 + 1 2 1 + 1 2 2 1 + 1 2 2 2 1 +``` + + +#### Pattern 24: + +``` +N = 4 + 1 + 1 1 + 2 0 2 + 3 0 0 3 +``` + + +#### Pattern 25: + +``` +N = 4 + * + * * * + * * * * * + * * * * * * * +``` + + +#### Pattern 26: + +``` +N = 4 + 1 + 2 1 2 + 3 2 1 2 3 + 4 3 2 1 2 3 4 +``` + + +#### Pattern 27: + +``` +N = 5 + 5 4 3 2 * + 5 4 3 * 1 + 5 4 * 2 1 + 5 * 3 2 1 + * 4 3 2 1 +``` + +#### Pattern 28: + +``` +N = 4 + * 0 0 0 * 0 0 0 * + 0 * 0 0 * 0 0 * 0 + 0 0 * 0 * 0 * 0 0 + 0 0 0 * * * 0 0 0 +``` + + + +#### Pattern 29: + +``` +N = 5 + 1 1 + 1 2 2 1 + 1 2 3 3 2 1 + 1 2 3 4 4 3 2 1 + 1 2 3 4 5 5 4 3 2 1 + +``` + + +#### Pattern 30: + +``` +N = 5 #####(N is always odd) + * * * * * + * * * * + * * + * * * * + * * * * * +``` + + +#### Pattern 31: + +``` +N = 5 + 1 1 + 2 2 +  3 3 + 4 4 + 5 + 4 4 +  3 3 + 2 2 + 1 1 +``` + + +#### Pattern 32: + +``` +N = 5 + 1 + 2 3 + 4 5 6 7 + 8 9 1 2 3 4 5 6 + 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 + +``` + + +#### Pattern 33: + +``` +N = 5 + 1 * * * * * + 2 * * * * + 3 * * * + 4 * * + 5 * + 4 * * + 3 * * * + 2 * * * * + 1 * * * * * + +``` diff --git a/Pattern-Problems/cpp/pattern01.cpp b/Pattern-Problems/cpp/pattern01.cpp new file mode 100644 index 0000000..a3798ed --- /dev/null +++ b/Pattern-Problems/cpp/pattern01.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + //LOOP TO PRINT MULTIPLE ROWS + for(int row=1; row<=n; row++){ + //WORK OF ONE ROW + + //LOOP TO PRINT MULTIPLE COLUMNS + for(int col=1; col<=row; col++){ + cout<<"1 "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int val = 1; + //LOOP TO PRINT MULTIPLE ROWS + for(int row=1; row<=n; row++){ + //WORK OF ONE ROW + + //LOOP TO PRINT MULTIPLE COLUMNS + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int val = 1; + //LOOP TO PRINT MULTIPLE ROWS + for(int row=1; row<=n; row++){ + //WORK OF ONE ROW + val = row; + + //LOOP TO PRINT MULTIPLE COLUMNS + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=n; row>=1; row--){ + for(int col=1; col<=row; col++){ + cout<<"1 "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=n; row>=1; row--){ + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int space=1; space<=n-row; space++){ + cout<<" "; + } + + for(int col=1; col<=row; col++){ + cout<<"1 "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int val = 1; + + for(int row=1; row<=n; row++){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + int val = row; + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=n; row>=1; row--){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + for(int col=1; col<=row; col++){ + cout<<"1 "; + } + + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=n; row>=1; row--){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + int val=1; + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + char val = 'A'; + for(int row=1; row<=n; row++){ + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=4; row>=1; row--){ + for(int col=1; col<=row; col++){ + cout<<(row+1)%2<<" "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + char val = 'D'-row+1; + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int val = 1; + for(int row=1; row<=n; row++){ + if(row%2==0){ + val = val+row; + int subVal = val-1; + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=n; row>=1; row--){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + char val = 'A'; + for(int col=1; col<=row; col++){ + cout<=1; col--){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + int val = n-row+1; + for(int col=1; col<=row; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=0; row<=n; row++){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + for(int col=row; col>=1; col--){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + if(n%2==0){ + cout<<"n should be an odd number"<=1; row--){ + for(int col=1; col<=row; col++){ + cout<<"* "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + if(n%2 == 0){ + cout<<"n should be odd"<=1; row--){ + + for(int spaces=1; spaces<=mid-row; spaces++){ + cout<<" "; + } + + int count = (2*row)-1; + for(int col=1; col<=count; col++){ + cout<<"* "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + if(n%2==0){ + cout<<"n should be an odd number"<=1; row--){ + for(int spaces=1; spaces<=mid-row; spaces++){ + cout<<" "; + } + + int count = (2*row)-1; + for(int col=1; col<=count; col++){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + int val=row; + for(int col=1; col<=row; col++){ + cout<=row){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + if(n%2==0){ + cout<<"n should be odd"<=1; row--){ + + for(int spaces=1; spaces<=row-1; spaces++){ + cout<<" "; + } + + for(int col=1; col<=row; col++){ + cout<<"*"; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + cout<<"1"< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + cout<<"1"< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + for(int col=1; col<=(2*row)-1; col++){ + cout<<"* "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int spaces=1; spaces<=n-row; spaces++){ + cout<<" "; + } + + int val=row; + while(val>=1){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + for (int col=n; col>=1; col--){ + if(col==row){ + cout<<"* "; + } + else{ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + for(int col=1; col<=n; col++){ + if(col==row){ + cout<<"* "; + } + else{ + cout<<"0 "; + } + } + cout<<"* "; + for(int col=n; col>0; col--){ + if(col==row){ + cout<<"* "; + } + else{ + cout<<"0 "; + } + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int col=1; col<=row; col++){ + cout<=1; col--){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + if(n%2==0){ + cout<<"n should be an odd number"<=1; row--){ + int numSpaces = (2*row) - 1; + int numCol = (n/2)-row+1; + for(int col=1; col<=numCol; col++){ + cout<<"* "; + } + + for(int spaces=1; spaces<= numSpaces; spaces++){ + cout<<" "; + } + + for(int col=1; col<=numCol; col++){ + cout<<"* "; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int num = (2*n)-1; + + for(int row=1; row<=n; row++){ + for(int col=1; col<=num; col++){ + if(col==row){ + cout<=1; row--){ + for(int col=1; col<=num; col++){ + if(col==row){ + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + int val=1; + int numCol=1; + + for(int row=1; row<=n; row++){ + for(int i=1; i<=numCol; i++){ + if(val>9){ + val=1; + } + cout< +using namespace std; + +int main(){ + cout<<"Enter n : "; + int n; + cin>>n; + + for(int row=1; row<=n; row++){ + + for(int spaces=1; spaces<=row-1; spaces++){ + cout<<" "; + } + + cout<=1; row--){ + for(int spaces=1; spaces<=row-1; spaces++){ + cout<<" "; + } + + cout< Date: Sun, 7 Oct 2018 18:15:59 +0530 Subject: [PATCH 2/2] patterns_python --- Pattern-Problems/python/PatternProblems.py | 574 ++++++++++++++++++ .../python/PatternProblemsRunner.py | 8 + 2 files changed, 582 insertions(+) create mode 100644 Pattern-Problems/python/PatternProblems.py create mode 100644 Pattern-Problems/python/PatternProblemsRunner.py diff --git a/Pattern-Problems/python/PatternProblems.py b/Pattern-Problems/python/PatternProblems.py new file mode 100644 index 0000000..f4a7393 --- /dev/null +++ b/Pattern-Problems/python/PatternProblems.py @@ -0,0 +1,574 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Oct 29 19:19:48 2017 +Pattern-Problems(Python) +@forked from:thedeepanshujain +@author: Vasudev +""" +def pattern1(n): + for i in range(n): + for j in range(i+1): + print('1',end=' ') + print() + return + +def pattern2(n): + val=1 + for i in range(n): + for j in range(i+1): + print(val,end=' ') + val=val+1 + print() + return + +def pattern3(n): + for i in range(n): + val=i+1 + for j in range(i+1): + print(val,end=' ') + val=val+1 + print() + return + +def pattern4(n): + i=n + while i>=1: + for j in range(i): + print('1',end=' ') + print() + i=i-1 + return + +def pattern5(n): + i=n + while i>=1: + for j in range(1,i+1): + print(j,end=' ') + print() + i=i-1 + return + +def pattern6(n): + for i in range(n): + space=n-(i+1) + while space>0: + print(' ',end=' ') + space=space-1 + for j in range(i+1): + print('1',end=' ') + print() + return + +def pattern7(n): + val=1 + for i in range(n): + space=n-(i+1) + while space>0: + print(' ',end=' ') + space=space-1 + for j in range(i+1): + print(val,end=' ') + val=val+1 + print() + return + +def pattern8(n): + for i in range(n): + space=n-(i+1) + while space>0: + print(' ',end='') + space=space-1 + for j in range(i+1): + print(i+j+1,end='') + print() + return + +def pattern9(n): + for i in range(n): + for space in range (1,i+1): + print(' ',end=' ') + for j in range(1,n-i+1): + print('1',end=' ') + print() + return + +def pattern10(n): + for i in range(n): + for space in range (1,i+1): + print(' ',end=' ') + for j in range(1,n-i+1): + print(j,end=' ') + print() + return + +def pattern11(n): + for i in range(n): + for j in range(i+1): + var=(chr)(65+i) + print(var,end=" ") + print() + return + +def pattern12(n): + i=n + while i>=1: + for j in range(i): + if(i%2==0): + print(1,end=' ') + else: + print(0,end=' ') + print() + i=i-1 + return + +def pattern13(n): + for i in range(n): + for j in range(i+1): + char=(chr)(n+64-i+j) + print(char,end=" ") + print() + return + +def pattern14(n): + i=1 + val=1 + while(i<=n): + j=1 + if(i%2==0): + val=val+i + evenRowVal=val-1 + while j<=i: + print(evenRowVal,end=' ') + evenRowVal=evenRowVal-1 + j=j+1 + else: + while j<=i: + print(val,end=' ') + val=val+1 + j=j+1 + print() + i=i+1 + return + +def pattern15(n): + i=1 + while i<=n: + j=n + val=65 + space=2 + while space<=i: + print(" ",end=' ') + space=space+1 + while j>=i: + char=(chr)(val) + print(char,end=' ') + val=val+1 + j=j-1 + val=val-1 + j=n + while j>=i: + char=(chr)(val) + print(char,end=' ') + val=val-1 + j=j-1 + print() + i=i+1 + return + +def pattern16(n): + i=1 + while i<=n: + val=n-i+1 + j=1 + while j<=i: + print (val,end=' ') + val=val+1 + j=j+1 + while j<=n: + print(n,end=' ') + j=j+1 + print() + i=i+1 + return + + +def pattern17(n): + i=1 + while i<=n: + space=n + while space>i: + print(" ",end=' ') + space=space-1 + j=2 + val=i-1 + while j<=i: + print(val,end=' ') + val=val-1 + j=j+1 + print(val,end=' ') + val=val+1 + j=2 + while j<=i: + print(val,end=' ') + val=val+1 + j=j+1 + print() + i=i+1 + return + +def pattern18(n): + m=(int)(n/2) + k=n-m + i=1 + while i<=m: + j=1 + while j<=i: + print("*",end=' ') + j=j+1 + print() + i=i+1 + i=1 + while i<=k: + j=k + while j>=i: + print("*",end=' ') + j=j-1 + print() + i=i+1 + return + +def pattern19(n): + m=(int)(n/2)+1 + k=n-m + i=1 + while i<=m: + space=m + while space>i: + print(" ",end=' ') + space=space-1 + j=1 + while j<=2*i-1: + print("*",end=' ') + j=j+1 + print() + i=i+1 + i=k + while i>=1: + space=k + while space>=i: + print(" ",end=' ') + space=space-1 + j=1 + while j<=2*i-1: + print("*",end=' ') + j=j+1 + print() + i=i-1 + return + +def pattern20(n): + m=(int)(n/2)+1 + k=n-m + i=1 + while i<=m: + space=m + while space>i: + print(" ",end=' ') + space=space-1 + j=1 + while j<=2*i-1: + print(j,end=' ') + j=j+1 + print() + i=i+1 + i=k + while i>=1: + space=k + while space>=i: + print(" ",end=' ') + space=space-1 + j=1 + while j<=2*i-1: + print(j,end=' ') + j=j+1 + print() + i=i-1 + return + +def pattern21(n): + i=1 + while i<=n: + space=n + while space>i: + print(" ",end=' ') + space=space-1 + j=1 + val=i + while(j<=2*i-1): + if ji: + print(val,end=' ') + val=val-1 + j=j+1 + print() + i=i+1 + return + +def pattern22(n): + m=(int)(n/2)+1 + k=n-m + i=1 + while i<=m: + space=2 + while space<=i: + print(" ",end=' ') + space=space+1 + j=1 + while(j<=i): + print("*",end=' ') + j=j+1 + print() + i=i+1 + i=k + while i>=1: + space=k + while space<=i: + print(" ",end=' ') + space=space+1 + j=1 + while j<=i: + print("*",end=' ') + j=j+1 + print() + i=i-1 + return +def pattern23(n): + i=1 + while i<=n: + j=1 + while j<=i: + if j==1 or j==i: + print(1,end=' ') + else: + print(2,end=' ') + j=j+1 + print() + i=i+1 + return + +def pattern24(n): + print(1) + i=2 + while i<=n: + j=1 + while j<=i: + if j==1 or j==i: + print(i-1,end=' ') + else: + print(0,end=' ') + j=j+1 + print() + i=i+1 + return + +def pattern25(n): + i=1 + while i<=n: + space=n + while space>i: + print(" ",end=' ') + space=space-1 + j=1 + while j<=i: + print("*",end=' ') + j=j+1 + j=2 + while j<=i: + print("*",end=' ') + j=j+1 + print() + i=i+1 + return + +def pattern26(n): + i=1 + while i<=n: + space=n + while space>i: + print(" ",end=' ') + space=space-1 + j=1 + val=i + while j<=i: + print(val,end=' ') + val=val-1 + j=j+1 + j=2 + val=2 + while j<=i: + print(val,end=' ') + val=val+1 + j=j+1 + print() + i=i+1 + return + +def pattern27(n): + i=1 + while i<=n: + j=n + val=n + while j>i: + print(val,end=' ') + val=val-1 + j=j-1 + print("*",end=' ') + j=1 + val=i-1 + while j=1: + if(j==i): + print("*",end=' ') + else: + print("0",end=' ') + j=j-1 + print() + i=i+1 + return + +def pattern29(n): + i=1 + while i<=n: + val=1 + j=1 + while j<=i: + print(val,end=' ') + val=val+1 + j=j+1 + while j<=n: + print(" ",end=' ') + j=j+1 + j=1 + val=i + while j<=i: + print(val,end=' ') + val=val-1 + j=j+1 + print() + i=i+1 + return + +def pattern31(n): + i=1 + while i<=n-1: + j=1 + while j<=n: + if j==i: + print(i,end=' ') + else: + print(" ",end=' ') + j=j+1 + j=1 + while j<=n-1: + if j==n-i: + print(i,end=' ') + else: + print(" ",end=' ') + j=j+1 + print() + i=i+1 + j=1 + while j<=n-1: + print(" ",end=' ') + j=j+1 + print(n,end=' ') + print() + i=1 + while i<=n-1: + j=1 + while j<=n: + if j==n-i: + print(j,end=' ') + else: + print(" ",end=' ') + j=j+1 + j=1 + while j<=n-1: + if j==i: + print(n-i,end=' ') + else: + print(" ",end=' ') + j=j+1 + print() + i=i+1 + return + +def pattern32(n): + i=1 + val=1 + k=1 + while i<=n: + j=1 + while j<=k: + if(val==10): + val=1 + print(val,end=' ') + val=val+1 + j=j+1 + k=k*2 + print() + i=i+1 + return + +def pattern33(n): + i=1 + while i<=n: + j=1 + while j<=n+1: + if j==i: + print(i,end=' ') + elif ji: + print("*",end=' ') + j=j+1 + print() + i=i+1 + i=1 + while i<=n-1: + j=1 + while j<=n+1: + if j==n-i: + print(j,end=' ') + elif j>n-i: + print("*",end=' ') + else: + print(" ",end=' ') + j=j+1 + print() + i=i+1 + return diff --git a/Pattern-Problems/python/PatternProblemsRunner.py b/Pattern-Problems/python/PatternProblemsRunner.py new file mode 100644 index 0000000..0d2bdaa --- /dev/null +++ b/Pattern-Problems/python/PatternProblemsRunner.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +""" +Created on Sun Oct 29 19:24:29 2017 +PatternProblems Runner File +@author: Vasudev +""" +from PatternProblems import pattern30 +pattern30(5) \ No newline at end of file