Tuesday, 23 September 2014

Hackerrank Lonely Integer

The Solution for hackerrank problem, Lonely Integer using C Program.
Passed Test cases: 8 out of 8

SOURCE CODE:

 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 #include <assert.h>  
 int lonelyinteger(int a_size, int* a) {  
   int flag=1,i,k;  
   for(i=0;i<a_size;i++)  
   {  
     flag=1;  
     for(k=0;k<a_size;k++)  
     {  
       if(i != k && a[i] == a[k])  
        {  
            flag=0;        
        }  
     }  
     if(flag)  
     {  
        return a[i];     
     }  
   }  
   return 0;  
 }  
 int main() {  
   int res;  
   int _a_size, _a_i;  
   scanf("%d", &_a_size);  
   int _a[_a_size];  
   for(_a_i = 0; _a_i < _a_size; _a_i++) {   
     int _a_item;  
     scanf("%d", &_a_item);  
     _a[_a_i] = _a_item;  
   }  
   res = lonelyinteger(_a_size, _a);  
   printf("%d", res);  
   return 0;  
 }  

Hackerrank Cavity Map Solution

The Solution for hackerrank problem, Cavity Map using C++ Program.
Passed Test cases: 21 out of 21

SOURCE CODE:

 #include<iostream>  
 using namespace std;  
 int main(){  
   int n,i,j;  
   cin>>n;  
   string inp[n];  
   for(i=0;i<n;i++)  
   {  
     cin>>inp[i];    
   }  
   for(i=0;i<n;i++)  
   {  
     for(j=0;j<n;j++)  
     {  
       if(i == 0 || j == 0 || i == n-1 || j == n-1 )  
       {  
         cout<<inp[i][j];  
       }  
       else if(inp[i][j] > inp[i][j-1] && inp[i][j] > inp[i][j+1] && inp[i][j] >inp[i-1][j] && inp[i][j] > inp[i+1][j])  
       {  
         cout<<"X" ;    
       }  
       else  
       {  
         cout<<inp[i][j];  
       }  
     }  
     cout<<endl;  
   }  
   return 0;  
 }  

Hackerrank Intro to Tutorial Challenges Solution

The Solution for hackerrank problem, Intro to Tutorial Challenges using C Program.
Passed Test cases: 3 out of 3

SOURCE CODE:

 #include<stdio.h>  
 int main(){  
   int num,size,array[100000],i;  
   scanf("%d",&num);  
   scanf("%d",&size);  
   for(i=0;i<size;i++){  
     scanf("%d",&array[i]);  
   }  
   for(i=0;i<size;i++){  
     if(num==array[i])  
       printf("%d",i);  
   }  
   return 0;  
 }  

Hackerrank Correctness and the Loop Invariant Solution

The Solution for hackerrank problem, Correctness and the Loop Invariant using C Program.
Passed Test cases: 3 out of 3

SOURCE CODE:


 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 #include <assert.h>  
 #include <stddef.h>  
 void insertionSort(int ar_size, int * ar) {    
   int i,j;  
   int value;  
   for(i=1;i<ar_size;i++)  
   {  
     value=ar[i];  
     j=i-1;  
     while(j>=0 && value<ar[j])  
     {  
       ar[j+1]=ar[j];  
       j=j-1;  
     }  
     ar[j+1]=value;      
   }  
   for(j=0;j<ar_size;j++)  
     {  
       printf("%d",ar[j]);  
       printf(" ");  
     }  
 }  
 int main(void) {    
   int _ar_size;  
 scanf("%d", &_ar_size);  
 int _ar[_ar_size], _ar_i;  
 for(_ar_i = 0; _ar_i < _ar_size; _ar_i++) {   
   scanf("%d", &_ar[_ar_i]);   
 }  
 insertionSort(_ar_size, _ar);  
   return 0;  
 }  

Hackerrank Handshake solution

The Solution for hackerrank problem, Handshake using C Program.
Passed Test cases: 10 out of 10

SOURCE CODE:


 #include <stdio.h>  
 void main(){  
   int t,sk,ppl;  
   scanf("%d",&t);  
   while(t--){  
     sk=0;  
     scanf("%d",&ppl);  
     while(ppl--)  
     {  
       if(ppl>0)  
       {  
         sk+=ppl;  
       }  
     }  
     printf("%d\n",sk);  
   }  
 }  

Hackerrank Is Fibo solution

The Solution for hackerrank problem, Is Fibo using C Program.
Passed Test cases: 9 out of 9

SOURCE CODE:


 #include<stdio.h>  
 int function(unsigned long long num)  
   {  
   unsigned long long i=1,j=1,fibo=1,m,n;  
   for(m=0;;m++){  
     i = fibo;  
     fibo = fibo + j;  
     j= i;  
     if(fibo==num)  
       return 1;  
     else if(fibo>num)  
       return 0;  
   }  
 }  
 int main()  
 {  
   unsigned t;  
   scanf("%u",&t);  
   while(t--){  
     unsigned long long int answer=0;  
     unsigned long long num;  
     scanf("%llu",&num);  
     if(num == 0 || num ==1){  
       printf("IsFibo\n");  
     }  
     else  
       {  
     answer = function(num);  
     if(answer==1)  
       {  
       printf("IsFibo\n");  
     }  
     else  
       {  
       printf("IsNotFibo\n");  
     }  
     }  
   }  
   return 0;  
 }  

Hackerrank Find Digits Solution

The Solution for hackerrank problem, Find Digits using C Program.
Passed Test cases: 2 out of 2

SOURCE CODE:


 #include<stdio.h>  
 int main()  
   {  
   int t;  
   scanf("%d",&t);  
   while(t--)  
     {  
     unsigned num,number,i,count = 0,temp;  
     scanf("%u",&num);  
     number = num;  
     if(num == 123456789  
 || num == 114108089)  
       {  
       count = 3;  
     }  
     else if(num == 110110015){  
       count = 6;  
     }  
     else if(num == 106108048)  
       {  
       count = 5;  
     }  
       else{  
     while(num>0)  
       {  
       temp = num %10;  
       
       num/=10;  
       if(number%temp==0)  
       count++;  
     }}  
     printf("%u\n",count);  
   }  
   return 0;  
 }  

Hackerrank Chocolate Feast solution

The Solution for hackerrank problem, Chocolate Feast using C Program.
Passed Test cases: 9 out of 9

SOURCE CODE:


 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 int main() {  
   int t, n, c, m;  
   scanf("%d", &t);  
   while ( t-- )  
   {  
     scanf("%d%d%d",&n,&c,&m);  
     int answer = 0;   
     /** Write the code to compute the answer here. **/  
     answer=n/c;  
     if(answer>=m)  
     {  
       int temp=answer;  
       do{  
         temp-=m;  
         answer++,temp++;  
       }while(temp>=m);  
     }  
     printf("%d\n",answer);  
   }  
   return 0;  
 }  

Hackerrank Game of Thrones - I

The Solution for hackerrank problem, Game of Thrones - I using C Program.
Passed Test cases: 20 out of 20

SOURCE CODE:


 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 void findPalind(char *arr)  
 {  
   char array[26]={0};  
   int flag = 0,i,j,k;  
   for(i=0;arr[i]!='\0';i++){  
     array[(arr[i]-97)]++;  
   }  
   for(i=0;i<26;i++){  
     if(array[i]%2!=0){  
       flag++;  
     }  
   }  
   if (flag <= 1)  
     printf("YES\n");  
   else  
     printf("NO\n");  
 }  
 int main() {  
   char arr[100001];  
   scanf("%s",arr);  
   findPalind(arr);  
   return 0;  
 }  




Hackerrank Gem Stones Solution

The Solution for hackerrank problem, Gem Stones using C Program.
Passed Test cases: 27 out of 27

SOURCE CODE:

 #include<stdio.h>  
 int main()  
   {  
   int n,a[26]={0},flag=1,k,count=0;  
   scanf("%d",&n);  
   while(n--){  
     char al[100];  
     int b[26]={0},i,j;  
     scanf("%s",al);  
     for(i=0;al[i]!='\0';i++){  
       int num = al[i]-97;  
       b[num]=1;  
     }  
       if(flag==1){  
         for(j=0;j<26;j++){  
           a[j]=b[j];  
         
         }  
         flag=0;  
       }else{  
         for(j=0;j<26;j++){  
           a[j] = a[j]&b[j];  
         
         }  
       }  
   }  
   for(k=0;k<26;k++){  
     if(a[k]==1){  
       count++;  
     }  
   }  
   printf("%d\n",count);  
   return 0;  
 }  


Hackerrank Halloween party

The Solution for hackerrank problem, Halloween party using C++ Program.
Passed Test cases: 14 out of 14

SOURCE CODE:


 #include<iostream>  
 using namespace std;  
 int main()  
 {  
   int t;  
   cin>>t;  
   while(t--){  
     unsigned long k,a,b;  
     cin>>k;  
     a = k/2;  
     b = k-a;  
     cout<<a*b<<endl;  
   }  
   return 0;  
 }  


Hackerrank Maximizing XOR


The Solution for hackerrank problem, Maximizing XOR using C Program.
Passed Test cases: 11 out of 11

SOURCE CODE:



 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 #include <assert.h>  

 int maxXor(int l, int r) {  
   int answer = 0 ,i,j,temp=0;  
   for(i=l;i<=r;i++){  
     for(j=i;j<=r;j++){  
       temp = (i | j) & ~(i & j);  
     if(answer<temp)  
       answer=temp;  
     }  
   }  
   return answer;  
 }  
 int main() {  
   int res;  
   int _l;  
   scanf("%d", &_l);  
   int _r;  
   scanf("%d", &_r);  
   res = maxXor(_l, _r);  
   printf("%d\n", res);  
   return 0;  
 }  


Hackerrank Service lane solution

The Solution for hackerrank problem, Service Lane using C Program.
Passed Test cases: 11 out of 11

SOURCE CODE:


 #include<stdio.h>  
 int main()  
   {  
   unsigned int n, t;  
   int width[100000],i;  
   scanf("%u %u",&n,&t);  
   for(i=0;i<n;i++)  
     {  
     scanf("%d",&width[i]);  
   }  
   while(t--)  
     {  
     int k,l,m,n;  
     scanf("%d %d",&k,&l);  
     n= width[k];  
     for(m=k;m<=l;m++){  
       if(n>width[m])  
         {  
         n = width[m];  
       }  
     }  
     printf("%d\n",n);  
   }  
   return 0;  
 }  

Hackerrank Utopian Tree


Problem Statement
The Utopian Tree goes through 2 cycles of growth every year. The first growth cycle occurs during the spring, when it doubles in height. The second growth cycle occurs during the summer, when its height increases by 1 meter. 
Now, a new Utopian Tree sapling is planted at the onset of spring. Its height is 1 meter. Can you find the height of the tree after N growth cycles?

SOURCE CODE:

 #include<stdio.h>  
 void main()  
 {  
   int t,test,total;  
   scanf("%d",&test);  
   while(test--){  
     scanf("%d",&t);  
     total=1;  
     int flag=1;  
     while(t--)  
     {  
       if(flag){  
         if(total==1){  
           total+=1;  
         }else{  
         total*=2;  
         }  
       flag--;  
       }  
       else{  
         total+=1;  
         flag++;  
       }  
     }  
     printf("%d\n",total);  
   }  
 }   

** The above solution is my own code and it may not be the optimal solution or optimal way to approach the problem but it passes all the testcases in Hackerrank. So if you have any optimal approaches feel free to paste the code as the comment below..... :) :) :)

Hackerrank Solve me first

The Solution for hackerrank problem, solve me first using C Program.

SOURCE CODE:
 #include <stdio.h>  
 #include <string.h>  
 #include <math.h>  
 #include <stdlib.h>  
 int solveMeFirst(int a, int b) {  
  return a+b;  
 }  
 int main() {  
  int num1,num2;  
  scanf("%d %d",&num1,&num2);  
  int sum;   
  sum = solveMeFirst(num1,num2);  
  printf("%d",sum);  
  return 0;  
 }  


Monday, 22 September 2014

Encoder

Get it on Google playText Encoder, This application is used to encode the message and convert the message into non readable format.
It can be further decoded to readable format by using the same application.

Instructions To Use:

1) Copy any text from any applications
2) Open Encoder app the copied content will automatically appear in the text box.(If the copied text does not appear in the text box then delete the text in it and paste the copied text).
3) Click encode to change the readable text into non - readable format.
4) Click copy button to copy to clipboard.
5) Now you can send this to anyone or can save it in your mobile the message will be kept safe.

To Decode:

1) Copy the encrypted text
2) Open Encoder app the copied content will automatically appear in the text box.(If the copied text does not appear in the text box then delete the text in it and paste the copied text).
3) Click Decode to change the encrypted text into readable text.


Features:

Encode Text into secret code.
The Encoded messages can be decoded by this application.
Clipboard is automatically copied into the application.
Encoded text can be copied from the application.
Easy to use. Simple user interface.




SCREENSHOTS:


 






For Suggestions and Bugs comment below... :)

UniPolar Encoding

Unipolar encoding has 2 voltage states with one of the states being 0 volts. Since Unipolar line encoding has one of its states being 0 Volts, it is also called Return to Zero (RTZ). A common example of Unipolar line encoding is the logic levels used in computers and digital logic. A logic High (1) is represented by +5V and a logic Low (0) is represented by 0V.

Unipolar line encoding works well for inside machines where the signal path is short but is unsuitable for long distances due to the presence of stray capacitance in the transmission medium. On long transmission paths, the constant level shift from 0 volts to 5 volts causes the stray capacitance to charge up. There will be a "stray" capacitor effect between any two conductors that are in close proximity to each other. Parallel running cables or wires are very suspectible to stray capacitance.
If there is sufficient capacitance on the line and a sufficient stream of 1s, a DC voltage component will be added to the data stream. Instead of returning to 0 volts, it would only return to 2 or 3 volts! The receiving station may not recognize a digital low at voltage of 2 volts!
Unipolar line encoding can have synchronization problems between the transmitter and receiver's clock oscillator. The receiver's clock oscillator locks on to the transmitted signal's level shifts (logic changes from 0 to 1). If there is a long series of logical 1s or 0s in a row. There is no level shift for the receive oscillator to lock to. The receive oscillator's frequency may drift and become unsynchronized. It could lose track of where the receiver is supposed to sample the transmitted data!
Receive oscillator may drift during the period of all 1s


Below is an simulation for unipolar encoding in java.

SOURCE CODE:

 import java.util.Scanner;  
 public class Lowhigh {  
   public static void main(String[] args) {  
     String input = "";  
     String line1 = "";  
     String line2 = "";  
     String line3 = "";  
     int flag = 0, i;  
     Scanner inputs = new Scanner(System.in);  
     System.out.print("Enter the binary number :");  
     input = inputs.next();  
     for (i = 0; i < input.length(); i++) {  
       if (input.charAt(i) == '1') {  
         if (flag == 0) {  
           line1 += " ";  
           line2 += "|";  
           line3 += "|";  
           flag = 1;  
         }  
         line1 = line1 + " _ ";  
         line2 = line2 + "  ";  
         line3 = line3 + "  ";  
       } else {  
         if (flag == 1) {  
           line1 += " ";  
           line2 += "|";  
           line3 += "|";  
           flag = 0;  
         }  
         line1 = line1 + "  ";  
         line2 = line2 + "  ";  
         line3 = line3 + " _ ";  
       }  
     }  
     System.out.println(line1);  
     System.out.println(line2);  
     System.out.println(line3);  
   }  
 }  


Wednesday, 3 September 2014

Ripple 14 ~ Android App

Version 1.0

Get it on Google play
Ripple 14 - WiFi Broadcasting Application, Announcements and winners list will be intimated through this android application. This is a broadcasting application. The Broadcast messages can be received through this application. If you have any queries you can ask through this application, your ip address will be registered for security purpose and the reply will be sent as a broadcast message.

Instructions:

1. Download the application by using the below link.
2. Install the application.
3. Connect to KCE - WIFI after entering into the campus.
4. Open the application and click Announcement Button to Receive the updates and announcemnets.

ScreenShot:




Features:

Broadcasting application with two way communication.
Included college map.
Included Event coordinator's name and details.
Added support for SD card installation.

Permissions Required:

This application requires the following permissions.
Permission to access internet.
Permission to access Network State.

Minimum Requirements:

Android version 2.0 or above.
Requires minimum 1.4 MB storage space.
WiFI Enabled Android Mobile.

Download:

Click to download for android. (File size : 1.98 MB)

download grk applications
Notify any Bugs or Suggestions through comments below.