CopyRight

If you feel that any content has violated the copy-Right law please be free to mail me.
I will take suitable action.
Thanks

Thursday 5 December 2013

Using Basic Vectors


VECTORS [STL :C++]

Want to sort an array of numbers but failing to choose a perfect sorting algorithm for the same looks cumbersome ? Want to optimize your solutions on sites like Codechef , HackerRank ? 
Then my friend C++ has the answer for you stored in it's STL library. 
STL library contains Vectors Container which is just like an array but with better functionalities. I have commented in the code the syntax and declaration of vector for easy understanding.

Question :
Given the list of numbers, you are to sort them in non decreasing order.

Input

t – the number of numbers in list, then t lines follow [t <= 10^6].

Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order.

Example

Input:
5
5
3
6
7
1
Output:
1
3
5
6
7

Answer : 
 #include <iostream>  
 #include <vector>  //for vector  
 #include <algorithm> //for sort  
 #include <stdio.h>  
 using namespace std;  
 int main()  
 {  
   long int t,i,temp;  
   vector<long int> v;      //Creating a Vector v  
   scanf("%ld",&t);  
   for(i=0;i<t;i++)  
   {  
     scanf("%ld",&temp);  
     v.push_back(temp);    //adding the element at the end of the vector  
   }  
   sort(v.begin(),v.end());    //the function "sort" is defined in <algorithm.h>  
                    //It takes parameters from the vector as to range which it has to sort  
   for(i=0;i<t;i++)  
   {  
     printf("%ld\n",v[i]);  
   }  
   return 0;  
 }  

Sunday 24 November 2013

Solution Facebook Hacker Cup 2013


Square Detector

You want to write an image detection system that is able to recognize different geometric shapes. In the first version of the system you settled with just being able to detect filled squares on a grid.
You are given a grid of N×N square cells. Each cell is either white or black. Your task is to detect whether all the black cells form a square shape.

Input

The first line of the input consists of a single number T, the number of test cases.
Each test case starts with a line containing a single integer N. Each of the subsequent N lines contain N characters. Each character is either "." symbolizing a white cell, or "#" symbolizing a black cell. Every test case contains at least one black cell.

Output

For each test case i numbered from 1 to T, output "Case #i: ", followed by YES or NO depending on whether or not all the black cells form a completely filled square with edges parallel to the grid of cells.

Constraints

1 ≤ T ≤ 20
1 ≤ N ≤ 20

Example

Test cases 1 and 5 represent valid squares. Case 2 has an extra cell that is outside of the square. Case 3 shows a square not filled inside. And case 4 is a rectangle but not a square.

Example input
5
4
..##
..##
....
....
4
..##
..##
#...
....
4
####
#..#
#..#
####
5
#####
#####
#####
#####
.....
5
#####
#####
#####
#####
#####

Example output 
Case #1: YES
Case #2: NO
Case #3: NO
Case #4: NO
Case #5: YES



Note: Just omit the last line in your outpfile cause that is extra and your file won't be 
accepted.

SOLUTION :
 #include <iostream>  
 #include <vector>  
 #include <algorithm>  
 #include <fstream>  
 using namespace std;  
 int main()  
 {  
   //ifstream in("in.txt");  
   //ofstream out("out.txt");  
   char a[21][21];  
   int t,num=0,n;  
   cin>>t;  
   //INPUT FROM THE USER  
   while(t--)  
   {  
     num++;  
     int i,j,flag=0,k,x,count=0,final_count=0;  
           vector<int> y;  
     cin>>n;  
     for(i=1;i<=n;i++)  
   {  
     for(j=1;j<=n;j++)  
     {  
       cin>>a[i][j];  
       if (a[i][j]=='#')  
       {  
         final_count++;  
       }  
     }  
   }  
   //STORING FIRST ROW WITH THE OCCURENCE OF "#"  
   for(i=1;i<=n;i++)  
   {  
     for(j=1;j<=n;j++)  
     {  
       if (a[i][j]=='#')  
       {  
           flag=1;  
           x=i;  
           y.push_back(j);  
           //cout<<i<<","<<j<<endl;  
       }  
     }  
     if(flag==1)  
     {  
       break;  
     }  
   }  
   int z=0;  
   for(i=1;i<=n;i++)  
   {  
     for(j=1;j<=n;j++)  
     {  
       if (a[i][j]=='#')  
       {  
         for(k=0;k<y.size();k++)  
         {  
           if(j==y[k])  
           {  
             count++;  
           }  
         }  
       }  
     }  
     if(count==y.size())  
     {  
         //cout<<"row "<<i<<"matched"<<endl;  
         if(x==i)  
         {  
           z++;  
           x++;  
         }  
     }  
     count=0;  
   }  
      //cout<<"z "<<z <<" y.size() "<<y.size()<<endl;  
   cout<<"Case #"<<num;  
   if(final_count!=(z*z))  
   {  
     cout<<": NO"<<endl;  
   }  
   else if(z==y.size())  
   {  
     cout<<": YES"<<endl;  
   }  
   else  
   {  
     cout<<": NO"<<endl;  
   }  
   }  
 return 0;  
 }  


WANT A PROPER EXPLANATION FOR THIS SOLUTION, JUST Comment below . 
#Happy Coding
#CodeScripter


Thursday 14 November 2013

Go Ahead,Do Mistakes,Take Challenges !

Be brave. Even if you’re not, pretend to be. No one can tell the difference. Don’t allow the phone to interrupt important moments. It’s there for your convenience, not the callers. Don’t be afraid to go out on a limb. That’s where the fruit is. 

Don’t burn bridges. You’ll be surprised how many times you have to cross the same river. Don’t forget, a person’s greatest emotional need is to feel appreciated. Don’t major in minor things. Don’t say you don’t have enough time. You have exactly the same number of hours per day that were given to Pasteur, Michaelangelo, Mother Teresa, Helen Keller, Leonardo Da Vinci, Thomas Jefferson, and Albert Einstein. Don’t spread yourself too thin. Learn to say no politely and quickly. Don’t use time or words carelessly. Neither can be retrieved.

Don’t waste time grieving over past mistakes Learn from them and move on. Every person needs to have their moment in the sun, when they raise their arms in victory, knowing that on this day, at his hour, they were at their very best.

Get your priorities straight. No one ever said on his death bed, ‘Gee, if I’d only spent more time at the office’. Give people a second chance, but not a third. Judge your success by the degree that you’re enjoying peace, health and love. Learn to listen. Opportunity sometimes knocks very softly. Leave everything a little better than you found it. Live your life as an exclamation, not an explanation. Loosen up. Relax. Except for rare life and death matters, nothing is as important as it first seems.

Never cut what can be untied. Never overestimate your power to change others. Never underestimate your power to change yourself. Remember that overnight success usually takes about fifteen years. Remember that winners do what losers don’t want to do. Seek opportunity, not security. A boat in harbor is safe, but in time its bottom will rot out. Spend less time worrying who’s right, more time deciding what’s right. Stop blaming others. Take responsibility for every area of your life.

Success is getting what you want. Happiness is liking what you get. The importance of winning is not what we get from it, but what we become because of it. When facing a difficult task, act as though it’s impossible to fail.

Saturday 15 June 2013

Website launch On my mind.!

Just when my exams are about to get over [17th June], what has come up in my mind is an idea for launching my own website.
the name will be the same as that of my blog and i will most probably redirect some of my blog's content on to that website. But what More I am thinking is of launching a video series on Youtube.
The idea about the video series is not yet final but it will most probably consist of Tutorials on C/C++ Java Data structure Algorithms, Adobe after effects ,Machine Learning etc.

Since every tutorial video will need a logo representing my Website, I have made an introductory 10 sec logo for my videos.



This video is made using Adobe After Effects which I am currently learning.

Rest,I am still thinking about different ideas about my website, and will work on them starting 17th itself.

Saturday 27 April 2013

Prime Numbers

PRIME NUMBERS Big Deal,Huh?


Prime Number is a natural number which has exactly two distinct natural number divisors1 and itself.

You can most probably figure out the first 10-15 primes by yourself manually. But then,here we are talking about Programming , writing code. So, the first thought that would have come into your mind  would be that of "Brute Force" approach !
Actually , you are right in thinking that checking every number till n [ n is our number till which we have to collect all primes] and dividing it by n-1 numbers to check weather it is divisible or not and so on. Brute Force as it's called.

But frankly speaking the complexity of this code/algorithm would be quite high and you don't want to that unless you don't understand the term  Complexity.

So, here comes the Savior The sieve of eratosthenes .
This algorithm is pretty straight forward and doesn't require nuclear science brains or any other brainstorming session for it's implementation.

Pseudo-code ! 
Input: an integer n > 1
 
Let A be an array of Boolean values, indexed by integers 2 to n,
initially all set to true.
 
for i = 2, 3, 4, ..., n :
  if A[i] is true:
    for j = i2, i2+i, i2+2i, ..., n:
      A[j] := false
  
Now all i such that A[i] is true are prime. 


The above Image very well illustrates the Algorithm. :)

Still have Doubts.?
This video may help I guess.


Hope your  fear of Prime Number has been conquered a little , but Believe me you are in the right direction of winning the battle.

For more such posts please comment or mail me the topics and I am happy to help. Don't orget to subscribe!  

Wednesday 10 April 2013

14 Interesting Facts About Google


14 Interesting Facts About Google

#1
The prime reason the Google home page is so bare is due to the fact that the founders didn’t know HTML and just wanted a quick interface. In fact it was noted that the submit button was a long time coming and hitting the RETURN key was the only way to burst Google into life.

#2
Due to the sparseness of the homepage, in early user tests they noted people just sitting looking at the screen. After a minute of nothingness, the tester intervened and asked ‘Whats up?’ to which they replied “We are waiting for the rest of it”. To solve that particular problem the Google Copyright message was inserted to act as a crude end of page marker.

#3
One of the biggest leap in search usage came about when they introduced their much improved spell checker giving birth to the “Did you mean…” feature. This instantly doubled their traffic, but they had some interesting discussions on how best to place that information, as most people simply tuned that out. But they discovered the placement at the bottom of the results was the most effective area.

#4
The infamous “I feel lucky” is nearly never used. However, in trials it was found that removing it would somehow reduce the Google experience. Users wanted it kept. It was a comfort button.

#5
Orkut is very popular in Brazil. Orkut was the brainchild of a very intelligent Google engineer who was pretty much given free reign to run with it, without having to go through the normal Google UI procedures, hence the reason it doesn’t look or feel like a Google application. They are looking at improving Orkut to cope with the loads it places on the system.

#6
Google makes changes small-and-often. They will sometimes trial a particular feature with a set of users from a given network subnet; for example Excite@Home users often get to see new features. They aren’t told of this, just presented with the new UI and observed how they use it.

#7
Google has the largest network of translators in the world

#8
They use the 20% / 5% rules. If at least 20% of people use a feature, then it will be included. At least 5% of people need to use a particular search preference before it will make it into the ‘Advanced Preferences’.

#9
They have found in user testing, that a small number of people are very typical of the larger user base. They run labs continually and always monitoring how people use a page of results.

#10
The name ‘Google’ was an accident. The original founders were going for 'Googol', but ended up with 'Google' due to a spelling mistake on a check that investors wrote to the founders.

#11
Gmail was used internally for nearly 2years prior to launch to the public. They discovered there was approximately 6 types of email users, and Gmail has been designed to accommodate these 6.

#12
They listen to feedback actively. Emailing Google isn’t emailing a blackhole.

#13
Employees are encouraged to use 20% of their time working on their own projects. Google News, Orkut are both examples of projects that grew from this working model.

#14
This wasn’t a technical talk so no information regarding any infrastructure was presented however they did note that they have a mantra of aiming to give back each page with in 500ms, rendered.

Source : 14 Interesting Facts About Google

The Google reCAPTCHA Project

The Google reCAPTCHA Project

The reCAPTCHA was originally created by Luis von Ahn, Ben Maurer, Colin McMillen, David Abraham and Manuel Blum and Google acquired it on September 16, 2009 for $27million.

We have all come across the ubiquitous captcha - the colourful images with distorted text - a reverse Turing test of sorts. These work because no algorithm at present can read distorted text as well as we humans do. However not all the distorted texts are unreadable by machines. About 200 million captchas are solved everyday, amounting to more than 150,000 hours of work each day. Considering the numbers involved, a safe captcha generation system was needed. Enter Google reCAPTCHA. To make a positive use of this immense human effort, the reCAPTCHA channels the effort spent solving captcha online into 'reading' books.

To archive human knowledge and to make information more accessible to the world, multiple projects are digitising physical books that were written before the computer age. The book pages are photographically scanned, and then transformed into text using "Optical Character Recognition" (OCR). The transformation into text is useful because scanning a book produces images, which are difficult to store on small devices, expensive to download, and cannot be searched. The problem is that OCR is not perfect.

reCAPTCHA improves the process of digitizing books by sending words that cannot be read by computers to the Web in the form of CAPTCHAs for humans to decipher. More specifically, each word that cannot be read correctly by OCR is placed on an image and used as a CAPTCHA. This is possible because most OCR programs alert you when a word cannot be read correctly and this also ensures that the image is unreadable by machines.
But if a computer can't read such a CAPTCHA, how does the system know the correct answer to the puzzle? Here's how: Each new word that cannot be read correctly by OCR is given to a user in conjunction with another word for which the answer is already known. The user is then asked to read both words. If they solve the one for which the answer is known, the system assumes their answer is correct for the new one. The system then gives the new image to a number of other people to determine, with higher confidence, whether the original answer was correct.

The system has been reported as displaying over 100 million CAPTCHAs every day, and among its subscribers are such popular sites as Facebook, TicketMaster, Twitter, Craigslist, and StumbleUpon. The Google reCAPTCHA project is astonishingly elegant and amazingly simple!

sources:
What is reCAPTCHA?
reCAPTCHA