From 1e9a0945668ae9588da72cf61135031299654159 Mon Sep 17 00:00:00 2001 From: Arvind Bakshi <38808197+abcool@users.noreply.github.com> Date: Sat, 19 Mar 2022 00:59:40 +0530 Subject: [PATCH 1/4] Create Patterns.java --- DS & Algo in Java/Patterns.java | 165 ++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 DS & Algo in Java/Patterns.java diff --git a/DS & Algo in Java/Patterns.java b/DS & Algo in Java/Patterns.java new file mode 100644 index 00000000..7bc5161a --- /dev/null +++ b/DS & Algo in Java/Patterns.java @@ -0,0 +1,165 @@ +/* package codechef; // don't place package name! */ + +import java.util.*; +import java.lang.*; +import java.io.*; + +/* Name of the class has to be "Main" only if the class is public. */ +class Codechef +{ + /* + * * * * + * * * * + * * * * + * * * * + * * * * + */ + private static void rectanglePattern(int rows, int cols){ + for(int i=0;i0;i--){ + for(int j=i;j>0;j--){ + System.out.print("*"); + } + System.out.println(); + } + } + + /* + * + ** + *** + **** + ***** + + */ + private static void halfPyramid(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=n;j++){ + if(j<=n-i) + System.out.print(" "); + else + System.out.print("*"); + } + System.out.println(); + } + } + + /* + 1 + 22 + 333 + 4444 + 55555 + */ + private static void halfPyramidNumber(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=i;j++){ + System.out.print(i); + } + System.out.println(); + } + } + + /* + 1 + 2 3 + 4 5 6 + 7 8 9 10 + 11 12 13 14 15 + */ + private static void floydTriangle(int n){ + int count=1; + for(int i=1;i<=n;i++){ + for(int j=1;j<=i;j++){ + System.out.print(count + " "); + count++; + } + System.out.println(); + } + } + + /* + + * * + ** ** + *** *** + ******** + ******** + *** *** + ** ** + * * + + */ + private static void butterfly(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=i;j++){ + System.out.print("*"); + } + int spaces = 2*n-2*i; + for(int j=1;j<=spaces;j++){ + System.out.print(" "); + } + for(int j=1;j<=i;j++){ + System.out.print("*"); + } + System.out.println(); + } + for(int i=n;i>=1;i--){ + for(int j=1;j<=i;j++){ + System.out.print("*"); + } + int spaces = 2*n-2*i; + for(int j=1;j<=spaces;j++){ + System.out.print(" "); + } + for(int j=1;j<=i;j++){ + System.out.print("*"); + } + System.out.println(); + } + } + public static void main (String[] args) throws java.lang.Exception + { + /*int rows = 5, cols=4; + hollowRectanglePattern(rows,cols);*/ + int n=5; + //invertedHalfPyramid(n); + //halfPyramid(n); + //halfPyramidNumber(n); + //floydTriangle(n); + butterfly(4); + } +} From 7dac4cf9b0b3104b7e181634505bcec429a7ade8 Mon Sep 17 00:00:00 2001 From: Arvind Bakshi <38808197+abcool@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:18:42 +0530 Subject: [PATCH 2/4] Added new patterns Added patterns: 1. inverted Pattern 2. 0-1 Pattern 3. rhombus Pattern 4. number Pattern 5. palindromic Pattern --- DS & Algo in Java/Patterns.java | 117 +++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/DS & Algo in Java/Patterns.java b/DS & Algo in Java/Patterns.java index 7bc5161a..4ff6dd75 100644 --- a/DS & Algo in Java/Patterns.java +++ b/DS & Algo in Java/Patterns.java @@ -151,6 +151,117 @@ private static void butterfly(int n){ System.out.println(); } } + /* + 1 2 3 4 5 + 1 2 3 4 + 1 2 3 + 1 2 + 1 + */ + private static void invertedPattern(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=(n-i)+1;j++){ + System.out.print(j+" "); + } + System.out.println(); + } + } + + /* + 1 + 0 1 + 1 0 1 + 0 1 0 1 + 1 0 1 0 1 + */ + private static void zeroOnePattern(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=i;j++){ + if((i+j)%2==0) + System.out.print("1 "); + else + System.out.print("0 "); + } + System.out.println(); + } + } + + /* + * * * * * + * * * * * + * * * * * + * * * * * + * * * * * + */ + private static void rhombusPattern(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=n-i;j++) + System.out.print(" "); + for(int j=1;j<=n;j++){ + System.out.print("* "); + } + System.out.println(); + } + } + + /* + 1 + 1 2 + 1 2 3 + 1 2 3 4 + 1 2 3 4 5 + + */ + private static void numberPattern(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=n-i;j++) + System.out.print(" "); + for(int j=1;j<=i;j++) + System.out.print(j + " "); + System.out.println(); + } + } + + /* + 1 + 2 1 2 + 3 2 1 2 3 + 4 3 2 1 2 3 4 + 5 4 3 2 1 2 3 4 5 + + */ + private static void palindromicPattern(int n){ + /*for(int i=1;i<=n;i++){ + for(int j=1;j<=n-i;j++) + System.out.print(" "); + + for(int j=i;j>=1;j--) + System.out.print(j); + + for(int j=2;j<=i;j++){ + System.out.print(j); + } + + System.out.println(); + }*/ + for(int i=1;i<=n;i++){ + int j; + for(j=1;j<=n-i;j++){ + System.out.print(" "); + } + int k=i; + for(;j<=n;j++){ + System.out.print(k--); + System.out.print(" "); + } + k=2; + for(;j<=n+i-1;j++){ + System.out.print(k++); + System.out.print(" "); + } + System.out.println(); + } + } public static void main (String[] args) throws java.lang.Exception { /*int rows = 5, cols=4; @@ -160,6 +271,10 @@ public static void main (String[] args) throws java.lang.Exception //halfPyramid(n); //halfPyramidNumber(n); //floydTriangle(n); - butterfly(4); + //butterfly(4); + //invertedPattern(5); + //zeroOnePattern(5); + //rhombusPattern(5); + numberPattern(5); } } From c8f00b086bb07a1a4cca81435c07d82d6c4ae9f4 Mon Sep 17 00:00:00 2001 From: Arvind Bakshi <38808197+abcool@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:39:54 +0530 Subject: [PATCH 3/4] Update Patterns.java Added star and zig-zag patterns --- DS & Algo in Java/Patterns.java | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/DS & Algo in Java/Patterns.java b/DS & Algo in Java/Patterns.java index 4ff6dd75..4b854e44 100644 --- a/DS & Algo in Java/Patterns.java +++ b/DS & Algo in Java/Patterns.java @@ -262,6 +262,51 @@ private static void palindromicPattern(int n){ System.out.println(); } } + + /* + * + *** + ***** + ******* + ******* + ***** + *** + * + + */ + private static void starPattern(int n){ + for(int i=1;i<=n;i++){ + for(int j=1;j<=n-i;j++) + System.out.print(" "); + for(int j=1;j<=(2*i)-1;j++) + System.out.print("*"); + System.out.println(); + } + for(int i=n;i>=1;i--){ + for(int j=1;j<=n-i;j++) + System.out.print(" "); + for(int j=1;j<=(2*i)-1;j++) + System.out.print("*"); + System.out.println(); + } + } + + /* + * * * + * * * * * * + * * * * + */ + private static void zigZagPattern(int n){ + for(int i=1;i<=3;i++){ + for(int j=1;j<=n;j++){ + if((i+j)%4==0 || (i==2 && j%4==0)) + System.out.print("* "); + else + System.out.print(" "); + } + System.out.println(); + } + } public static void main (String[] args) throws java.lang.Exception { /*int rows = 5, cols=4; @@ -275,6 +320,9 @@ public static void main (String[] args) throws java.lang.Exception //invertedPattern(5); //zeroOnePattern(5); //rhombusPattern(5); - numberPattern(5); + //numberPattern(5); + //palindromicPattern(5); + //starPattern(4); + zigZagPattern(13); } } From 6176d1eba69e12fc4f2f644e1486ed33b9a7e3d9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 30 Mar 2022 08:58:37 +0000 Subject: [PATCH 4/4] Bump minimist from 1.2.5 to 1.2.6 in /js/generate-table-node Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6) --- updated-dependencies: - dependency-name: minimist dependency-type: indirect ... Signed-off-by: dependabot[bot] --- js/generate-table-node/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/generate-table-node/package-lock.json b/js/generate-table-node/package-lock.json index 12da6380..29111974 100644 --- a/js/generate-table-node/package-lock.json +++ b/js/generate-table-node/package-lock.json @@ -1412,9 +1412,9 @@ } }, "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "ms": { "version": "2.1.2",