Skip to content

Commit

Permalink
Add Day 5 question
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhavBahl committed Dec 26, 2018
1 parent 01a7efc commit 98b7853
Show file tree
Hide file tree
Showing 20 changed files with 1,530 additions and 1 deletion.
2 changes: 1 addition & 1 deletion day4/README.md
Expand Up @@ -289,7 +289,7 @@ print("Number of vowels in the string are : ",count)
```

## [Solution](./Python/Shashankvowels.py)
```Python
```py
"""
* @author: Shashank Jain
* @date: 25/12/2018
Expand Down
27 changes: 27 additions & 0 deletions day5/Java/Pattern1.java
@@ -0,0 +1,27 @@
import java.util.Scanner;

/***
* Pattern #1
* input = 5
* 1
* 1 2
* 1 2 3
* 1 2 3 4
* 1 2 3 4 5
*/

public class Pattern1 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #1 ===== */");
Scanner input = new Scanner (System.in);
int n = input.nextInt(), i, j;

// Print the pattern
for (i=1; i<=n; i++) {
for (j=1; j<=i; j++) {
System.out.print(j + " ");
}
System.out.println("");
}
}
}
32 changes: 32 additions & 0 deletions day5/Java/Pattern2.java
@@ -0,0 +1,32 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

import java.util.Scanner;

/**
* Pattern #2 (Floyds Triangle)
* input = 4
* 1
* 2 3
* 4 5 6
* 7 8 9 10
*/

public class Pattern2 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #2 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j, count=0;

// Print the pattern
for (i=1; i<= n; i++) {
for (j=1; j<=i; j++) {
count++;
System.out.print(count + " ");
}
System.out.println("");
}
}
}
42 changes: 42 additions & 0 deletions day5/Java/Pattern3.java
@@ -0,0 +1,42 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* Pattern #3
* input = 4
* 1
* 1 2
* 1 2 3
* 1 2 3 4
* 1 2 3
* 1 2
* 1
*/

import java.util.Scanner;

public class Pattern3 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #3 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

// Print the upper half
for (i=1; i<=n; i++) {
for (j=1; j<=i; j++) {
System.out.print(j + " ");
}
System.out.println("");
}

// Print the lower half
for (i=n-1; i>=1; i--) {
for (j=1; j<=i; j++) {
System.out.print(j + " ");
}
System.out.println("");
}
}
}
41 changes: 41 additions & 0 deletions day5/Java/Pattern4.java
@@ -0,0 +1,41 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* 1
* 2 3 2
* 3 4 5 4 3
* 4 5 6 7 6 5 4
* 5 6 7 8 9 8 7 6 5
*/

import java.util.Scanner;

public class Pattern4 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #4 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

for (i=1; i<=n; i++) {
// Print left white spaces
for (j=n; j>i; j--) {
System.out.print(" ");
}

// Print the numbers
for (j=i; j<=(2*i-1); j++) {
System.out.print(j + " ");
}

for (j=(2*i-1) - 1; j>=i; j--) {
System.out.print(j + " ");
}

System.out.println("");
}

}
}
38 changes: 38 additions & 0 deletions day5/Java/Pattern5.java
@@ -0,0 +1,38 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* input = 5
*
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
*/

import java.util.Scanner;

public class Pattern5 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #5 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

// Print the pattern
for (i=1; i<=n; i++) {
// Print whitet spaces
for (j = 1; j < i; j++) {
System.out.print(" ");
}

// Print asterisk
for (j = 1; j <= (2 * n - (2 * i - 1)); j++) {
System.out.print("* ");
}
System.out.println("");
}
}
}
55 changes: 55 additions & 0 deletions day5/Java/Pattern6.java
@@ -0,0 +1,55 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* input = 4
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
*/

import java.util.Scanner;

public class Pattern6 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #6 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

// Print upper pyramid
for (i=1; i<=n; i++) {
// Print white spaces
for (j=1; j<=n-i; j++) {
System.out.print(" ");
}

// Print asterisks
for (j=1; j<=(2*i - 1); j++) {
System.out.print("* ");
}

System.out.println("");
}

// Print lower pyramid
for (i=n-1; i>=1; i--) {
// Print white spaces
for (j=1; j<=n-i; j++) {
System.out.print(" ");
}

// Print asterisks
for (j=1; j<=(2*i - 1); j++) {
System.out.print("* ");
}

System.out.println("");
}
}
}
64 changes: 64 additions & 0 deletions day5/Java/Pattern7.java
@@ -0,0 +1,64 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* input = 4
*
* * * * * * * * * *
* * * * * * *
* * * * *
* * *
* * * * *
* * * * * * *
* * * * * * * * * *
*/

import java.util.Scanner;

public class Pattern7 {
public static void main (String[] args) {
System.out.println("/* ===== Pattern #7 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

// Print upper half
for (i=1; i<=n; i++) {
for (j=1; j<=2*n; j++) {

// Print upperleft pattern
if (i+j <= n+1)
System.out.print("*");
else
System.out.print(" ");

// Print upperright pattern
if (i>j-n)
System.out.print(" ");
else
System.out.print("*");
}
System.out.println("");
}

// Print lower half
for (i=1; i<=n; i++) {
for (j=1; j<=2*n; j++) {

// Print lower left pattern
if (j>i)
System.out.print(" ");
else
System.out.print("*");

// Print lower right pattern
if (i+j < 2*n+1)
System.out.print(" ");
else
System.out.print("*");
}
System.out.println("");
}
}
}
57 changes: 57 additions & 0 deletions day5/Java/Pattern8.java
@@ -0,0 +1,57 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

/**
* input = 5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*/

import java.util.Scanner;

public class Pattern8 {
public static void main(String[] args) {
System.out.println("/* ===== Pattern #8 ===== */");
Scanner input = new Scanner(System.in);
int n = input.nextInt(), i, j;

// Print upper pattern
for (i=1; i<=n; i++) {
for (j=1; j<=2*n; j++) {
if (j<=n) {
if (i<j) System.out.print(" ");
else System.out.print("* ");
} else {
if (i+j < 2*n + 1) System.out.print(" ");
else System.out.print("* ");
}
}
System.out.println("");
}

// Print lower pattern
for (i=1; i<=n; i++) {
for (j=1; j<=2*n; j++) {
if (j<=n) {
if (i+j>n+1) System.out.print(" ");
else System.out.print("* ");
} else {
if (i > j-n) System.out.print(" ");
else System.out.print("* ");
}
}
System.out.println("");
}
}
}
20 changes: 20 additions & 0 deletions day5/JavaScript/pattern1.js
@@ -0,0 +1,20 @@
/**
* @author MadhavBahlMD
* @date 26/12/2018
*/

function pattern1 (num) {
console.log ("/* ===== Pattern #1 ===== */");

for (let i=1; i<=num; i++) {
// we will store the output for each line in a string
// since console.log would print and take the pointer to next line
let currentLine = '';
for(let j=1; j<=i; j++) {
currentLine += j + ' ';
}
console.log (currentLine);
}
}

pattern1(5);

0 comments on commit 98b7853

Please sign in to comment.