Skip to content

Commit

Permalink
day18 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Jan 15, 2019
1 parent 995dc51 commit 07e3991
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 0 deletions.
44 changes: 44 additions & 0 deletions day18/Java/Freq.java
@@ -0,0 +1,44 @@
/*
* 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 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Freq {
public static void main(String []args)
{
int n;int i;int t;int k=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements in the array ");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter elements of the array ");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
Arrays.sort(arr);
if(n!=1){
if(arr[0]==arr[1])
k=1;
}
else
System.out.println("frequency of "+arr[0]+" is "+1);
for(i=1;i<n;i++)
{
if(arr[i]==arr[i-1])
k++;
else
{
System.out.println("frequency of "+arr[i-1]+" is "+k);
k=1;
}
}
if(n!=1)
System.out.println("frequency of "+arr[i-1]+" is "+k);
}
}
41 changes: 41 additions & 0 deletions day18/Java/Power.java
@@ -0,0 +1,41 @@
/*
* 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 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Power {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n,p;int i,j;int k=0;
System.out.println("Enter size of the array ");
n=sc.nextInt();
ArrayList<Integer> arr1 = new ArrayList<Integer>(n);
ArrayList<Integer> arr2 = new ArrayList<Integer>(n);
System.out.println("Enter elements of the first array ");
for(i=0;i<n;i++)
arr1.add(sc.nextInt());
System.out.println("Enter elements of the second array ");
for(i=0;i<n;i++)
arr2.add(sc.nextInt());
System.out.println("Enter power");
p=sc.nextInt();
for(i=0;i<n;i++)
{
int t=(int)(Math.pow(arr1.get(i),p));
if(arr2.contains(t))
k++;
}
if(k==n)
System.out.println("true");
else
System.out.println("false");
}
}
36 changes: 36 additions & 0 deletions day18/Java/Unique.java
@@ -0,0 +1,36 @@
/*
* 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 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Unique {
public static void countUniques(int arr[])
{
int k=1;
for(int i=1;i<arr.length;i++)
{
if(arr[i]!=arr[i-1])
k++;
}
System.out.println("Number of unique elements = "+k);
}
public static void main(String []args)
{
int n;int i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter elements of the array ");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
countUniques(arr);
}
}
122 changes: 122 additions & 0 deletions day18/README.md
Expand Up @@ -81,6 +81,50 @@ function printFrequency (freqObj) {
freqCounter ([ 1, 2, 3, 1, 3, 4, 4, 4, 4, 2, 5]);
```

## Java Implementation

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

```java
/**
* @date 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Freq {
public static void main(String []args)
{
int n;int i;int t;int k=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements in the array ");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter elements of the array ");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
Arrays.sort(arr);
if(n!=1){
if(arr[0]==arr[1])
k=1;
}
else
System.out.println("frequency of "+arr[0]+" is "+1);
for(i=1;i<n;i++)
{
if(arr[i]==arr[i-1])
k++;
else
{
System.out.println("frequency of "+arr[i-1]+" is "+k);
k=1;
}
}
if(n!=1)
System.out.println("frequency of "+arr[i-1]+" is "+k);
}
}
```

### Python Implementation

#### [Solution](./Python/A_Frequency_Counter.py)
Expand Down Expand Up @@ -202,6 +246,42 @@ function countUniques (arr) {
console.log (`Number of unique elements = ${countUniques([1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 7])}`);
```

## Java Implementation

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

```java
/**
* @date 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Unique {
public static void countUniques(int arr[])
{
int k=1;
for(int i=1;i<arr.length;i++)
{
if(arr[i]!=arr[i-1])
k++;
}
System.out.println("Number of unique elements = "+k);
}
public static void main(String []args)
{
int n;int i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of elements");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter elements of the array ");
for(i=0;i<n;i++)
arr[i]=sc.nextInt();
countUniques(arr);
}
}
```

### Python Implementation

#### [Solution](./Python/B_Count_Uniques.py)
Expand All @@ -218,6 +298,7 @@ def countUniques(data):
data = [1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 7]
print("Number of unique elements =", countUniques(data))
```

***

## Question 3 -- Check Power N
Expand Down Expand Up @@ -298,6 +379,47 @@ console.log (checkPowerN ([1, 2, 3, 4], [4, 9, 1, 16], 2));
console.log (checkPowerN ([3, 4, 5, 2], [1, 2, 3], 4));
```

## Java Implementation

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

```java
/**
* @date 14/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class Power {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
int n,p;int i,j;int k=0;
System.out.println("Enter size of the array ");
n=sc.nextInt();
ArrayList<Integer> arr1 = new ArrayList<Integer>(n);
ArrayList<Integer> arr2 = new ArrayList<Integer>(n);
System.out.println("Enter elements of the first array ");
for(i=0;i<n;i++)
arr1.add(sc.nextInt());
System.out.println("Enter elements of the second array ");
for(i=0;i<n;i++)
arr2.add(sc.nextInt());
System.out.println("Enter power");
p=sc.nextInt();
for(i=0;i<n;i++)
{
int t=(int)(Math.pow(arr1.get(i),p));
if(arr2.contains(t))
k++;
}
if(k==n)
System.out.println("true");
else
System.out.println("false");
}
}
```

### Python Implementation

#### [Solution](./Python/C_Check_Power_N.py)
Expand Down

0 comments on commit 07e3991

Please sign in to comment.