diff --git a/Pattern-Problems/.DS_Store b/Pattern-Problems/.DS_Store new file mode 100644 index 0000000..20a8cdc Binary files /dev/null and b/Pattern-Problems/.DS_Store differ 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<=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 diff --git a/contributors.md b/contributors.md index 564eb97..b38a3ea 100644 --- a/contributors.md +++ b/contributors.md @@ -36,4 +36,5 @@ 33. [Ramy Gamal](https://github.com/Raamyy) 30. [Abinash Maharana](https://github.com/ab1nash) 34. [Shrey Aryan](https://github.com/shrey183) -34. [Your Name](https://github.com/yourusername) \ No newline at end of file +35. [Deepanshu Jain](https://github.com/thedeepanshujain) +35. [Your Name](https://github.com/yourusername)