Monday, 11 August 2014

Exciting week !

This week was full of ups and downs (I like it ;) ). I started practicing div 2 500 problems on TopCoder but after 2 days I was having loads of academic work pending and unfortunatley I had to give up my idea of solving 3 problems a day . But I didn't stop coding . Everyday I was learning new & exciting stuffs . I started learning python and C++ (OOPS part) I fell ill also(Now I am fit) .

One of my batch mate  asked me about the working of the square root function I told him that it should behave like a standard function with some iteration by which it outputs the answer to a particular level of precision and then while learning python I came across Newton Raphson method to calculate square root of a given number . I was very excited to see such method .Its like -

suppose we want to calculate the sqrt of N -
1. Take a rough approximation of lets say x = N/2 (It can be taken anything but it is advised to make it close to the square root of N)
2.  Iterate -
                 y = (x + N/x)/2
                 x = y
3. stop iterating when you reach to a particular level of precision lets say 0.00001

 sqrt(N)
{
     x = N/2
     while(1)
    {  y = (x+N/x)/2
        if(abs(y-x)<0.00001)break
        x = y
    }
   return x
}
Wondering whether if this is the method behind the built in function sqrt ... Gonna search for it .

Yesterday, I gave an online contest on Codechef which was conducted by IIIT Delhi's programming club and got 362nd rank .. All questions were easy but I could solve only 2/5 due to lack of Algorithmic knowledge .

Thanks for reading and keep coding !

Monday, 4 August 2014

Practice Session

So, once again I am shifting to TopCoder to hone my programming skills .This time I am doing Div 2 500 problems . I am forming a team to apply for ICPC regionals . First ,we need to qualify for the onsite regional contest and if we are able to do that it will be great as we are just in our 2nd year and with very less experience in programming . Lets see what happens.

This week I was doing random problems and participated in Codechef's Long contest which is still going on . I've already done 2 problems in the contest .I am participating in Codevita also which will be conducted on Aug. 12.
I've written a C++ program for BFS and will try to apply it on some graph problems .  

Thanks for reading . 

Sunday, 27 July 2014

Lucky Start in new semester

I reached hostel on 20th July afternoon. After taking rest for sometime I was ready for the Codechef's Cook Off contest . I started off well by submitting the first problem in the 7th minute . That was a very simple problem,  after that I attempted one more easy problem but made a very simple mistake and got penalized for that . Penalty was 20 extra minutes in my actual time . It was very frustrating that in an easy problem I missed one small condition and straight away I was penalized heavily for that but after one wrong attempt I submitted it successfully . Luckily I completed all the problems that were within my reach in time as just after submitting the second problem current went off .
I got 454th rank overall in the contest.

This week I was doing problems randomly as I was busy getting prepared to attend the classes and adjusting in a new room .
I did a problem on floating numbers and got a tip from a senior while doing it from a senior that if we enter a floating no. from the user like 0.02 it gets stored in the memory as 0.0199999999...(you can't see it as while printing the no. it shows 0.02 only ) while converting the decimal parts in binary the precision is not infinite so these things happen and thus a bug may easily enter our 'bug free looking' program .So,its advisable to use string to take the no. from the user and then manipulate it accordingly .
 
I've made a time table for myself I hope it will help me to manage my time properly . I know that managing programming and studies will going to be a challenging task for me but I'll try my best.

Thanks for reading and keep coding. 

Monday, 21 July 2014

New semester new story.

My 3rd semester is just about to start within a day from now.I'll try my best to make full use of time and the resources I have in this semester.
Just last night I participated in Codechef's Cook Off and did 2/5 problems . These two problems were very easy the other three were somewhat difficult out of those 3 two were touching the concepts of graph theory.
I made a wrong submission that costed me a penalty of 20 mins. otherwise I would have been in under 300 for sure but still I got 453 rank.

I got a method to calculate both LCM and HCF and that too very fast O(LogN). Yes,if you know it already I am talking about Euclid's GCD theorem.

Its like this -
Lets say we want to calculate GCD(Greatest Common Divisor or Highest Common Factor) of two given numbers lets say A,B .

So, pseudo code of the algorithm looks like this -
START-
GCD(A,B):
    if B>A return GCD(B,A)
    else:
        if A%B==0 return B
        else return GCD(B,A%B)
END
For example lets say A=12,B=18
calling GCD(12,18)
so as B>A it returns GCD(18,12)
then as 18%12=6 which is not equal to 0 it returns GCD(12,6)
but now as 12%6=0 it finally returns 6 . So, 6 is the GCD of 12,18

This method is very old yet very effective method to calculate the Highest Common Factor of given two numbers.

Now to calculate LCM all we need to do is just multiplay the no. A & B and divide the product with the GCD of A & B.
For example lets say A=12,B=18
So, LCM of 12,18 will be 12*18/GCD(12,18) = 12*18/6 = 36
Time Complexity of this algorithm is also O(LogN) as multiplication is O(1) and GCD is O(LogN)
So,Now we have two very effective algorithms to calculate HCF,LCM of two numbers .

Thanks for reading and Happy Coding :) .

Tuesday, 15 July 2014

A Busy Week..

This week I was very busy . I went to my Guru ji's(Spiritual Teacher) town to celebrate Guru Poornima with my family . Its an Indian festival dedicated to teachers. Word 'guru' is made of two sanskrit words 'gu' which means darkness and 'ru' which means remover.Whatever little I've achieved in my life is due to the teachings and blessings of my teachers .

I was trying to learn Breadth First Search this week . Now, I know the basic idea of Breadth First Search but don't know how to code it properly .I would like to add this graph searching technique in my armory ASAP .

My summer vacation is coming to an end .On 20th July I'll be moving out of my hometown for another amazing semester. This time I'll meet a whole new array of freshers . Really getting excited to search for good programmers out their .

The journey has just begun .


Thanks for reading and keep coding .