Skip to content

Commit

Permalink
day 24 and 25 (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Feb 7, 2019
1 parent 6669ac6 commit be14797
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 0 deletions.
68 changes: 68 additions & 0 deletions day24/Java/circularRotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;

/**
* @date 03/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class circularRotation {
public static boolean circular(List a1,List a2)
{
int p;int c=0;int i,j=0;
if(a1.size()!=a2.size())
return false;
else
{
p=a2.indexOf(a1.get(0));
if(p!=-1)
{
for(i=p;i<a2.size();i++)
{
if(a2.get(i)==a1.get(j))
{
c++;
j++;
}
else
break;
}
for(i=0;i<p;i++)
{
if(a2.get(i)==a1.get(j))
{
c++; j++;
}
else
break;
}
}
if(c==a1.size())
return true;
else
return false;
}

}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int m,n,i;
ArrayList<Integer> a = new ArrayList<Integer>();
ArrayList<Integer> a2 = new ArrayList<Integer>();
System.out.println("Enter size and insert elements into first array ");
m=sc.nextInt();
for(i=0;i<m;i++)
a.add(sc.nextInt());
System.out.println("Enter size and insert elements into second array ");
n=sc.nextInt();
for(i=0;i<n;i++)
a2.add(sc.nextInt());
boolean res = circular(a,a2);
System.out.println(res);
}
}
68 changes: 68 additions & 0 deletions day24/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,72 @@ def main
end

main
```

## Java Implementation

### [Solution](./Java/circularRotation.java)

```java
/**
* @date 03/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class circularRotation {
public static boolean circular(List a1,List a2)
{
int p;int c=0;int i,j=0;
if(a1.size()!=a2.size())
return false;
else
{
p=a2.indexOf(a1.get(0));
if(p!=-1)
{
for(i=p;i<a2.size();i++)
{
if(a2.get(i)==a1.get(j))
{
c++;
j++;
}
else
break;
}
for(i=0;i<p;i++)
{
if(a2.get(i)==a1.get(j))
{
c++; j++;
}
else
break;
}
}
if(c==a1.size())
return true;
else
return false;
}

}
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int m,n,i;
ArrayList<Integer> a = new ArrayList<Integer>();
ArrayList<Integer> a2 = new ArrayList<Integer>();
System.out.println("Enter size and insert elements into first array ");
m=sc.nextInt();
for(i=0;i<m;i++)
a.add(sc.nextInt());
System.out.println("Enter size and insert elements into second array ");
n=sc.nextInt();
for(i=0;i<n;i++)
a2.add(sc.nextInt());
boolean res = circular(a,a2);
System.out.println(res);
}
}
```
60 changes: 60 additions & 0 deletions day25/Java/rotateTile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;

/**
* @date 3/02/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class rotateTile {
public static int[][] rotate(int arr[][])
{
int i,j,ri=0;
int rj=arr.length-1;
int rot[][]=new int[arr.length][arr.length];
for(i=0;i<arr.length;i++)
{
for(j=0;j<arr.length;j++)
{
rot[ri][rj]=arr[i][j];
ri++;
}
rj--; ri=0;
}
return rot;
}
public static void main(String []args)
{
int n,i,j;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int ri=0,rj=n-1;
int arr[][]=new int[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
int rot[][]=rotate(arr);
System.out.println("Rotated matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(rot[i][j]+" ");
}
System.out.println();
}
}
}
60 changes: 60 additions & 0 deletions day25/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,64 @@ rotateTile ([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);

```js
To be added
```

## Java Implementation

### [Solution](./Java/rotateTile.java)

```java
/**
* @date 3/02/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class rotateTile {
public static int[][] rotate(int arr[][])
{
int i,j,ri=0;
int rj=arr.length-1;
int rot[][]=new int[arr.length][arr.length];
for(i=0;i<arr.length;i++)
{
for(j=0;j<arr.length;j++)
{
rot[ri][rj]=arr[i][j];
ri++;
}
rj--; ri=0;
}
return rot;
}
public static void main(String []args)
{
int n,i,j;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int ri=0,rj=n-1;
int arr[][]=new int[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
int rot[][]=rotate(arr);
System.out.println("Rotated matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(rot[i][j]+" ");
}
System.out.println();
}
}
}
```

0 comments on commit be14797

Please sign in to comment.