Tuesday, August 11, 2009

Memories of IIIT !!!

After a long time today I got a chance to write something again. Two precious year in IIIT Hyd...... seems like a wonderful dream. It was my dream to be a part of such a wonderful place and I am really thankful to God for his grace and one of my best frind Rajiv Singh to encourage me. Thanks Rajiv .

It was two most learning year of my life. This place taught me to think differently and boldly. Last one year was most important as here I changed my track and spent a lot of time in one thing which always created problem to me that is "programming". Some of my college mate might think that it is because of a bloody thing "al****ca" of which I had to be a part just like most of my class mates.

I still rememer how bad I was in programming, I always had to take help from Amit, mak ( specially for debugging my own code ).I did a different thing as I used the learning from that place "al****" to develop my problem solving skills. Then to evaluate myself started coding on spoj.pl which helped me a lot. I learnt a lot from different online tutorial, papers and blogs and achieved a very good rank.

It is really very satisfying when you see that your code is accepted on that portal. I spent a lot of sleepless night in coding on that portal. I still remember a problem which took me 21-22 days to solve, It was not uploading because of one minor base case. One day suddenly I wake up and immediately went to that portal coz I dont know how while sleeping I got the a clue of why it was not uploading . After making appropriate change I was sure that it is going to be upload and it uploaded .

I really miss those things a lot. I dont want to start those things again as I have better and more important works to do...................

Thursday, September 25, 2008

Taste of New Languages!!!!!!!

yesterday i code something in Python , after spending some time with it i realize that it made job of programmer quite easy, though Python , perl are scripting languages but very powerful. To handle very long numbers in c/c++ is not an easy task even simple arithmetic of huge number which we do using string is not very easy , it need a close observation and long code but in python it took only 10-12 lines.

While working on a problem i normally check the time taken by best solution , strangely people achieved unbelievable small time, i always amazed by seeing this, what data structure they use , what algorithm they use. After seeing that i always tell me that i have a loooooooooong way to go :)

Saturday, September 6, 2008

Factorial !!!!!!!!!!!!

Today i saw a problem which was asked often in technical round of good companies.
Problem : Finding the first non zero digit in the factorial of a number ( for 5! = 120 first non zero digit is 2 ).
Solution : If number is such that its factorial is within the range of even long long then we can use any brute force method like removing digit one by one till we don't get first non zero digit ( though it wont be efficient ).

Here is better solution , i am not claiming it is best , if any one know better please comment it.
We can easily calculate number of zero in the factorial of a number by dividing the number first by 5 then 5 ^ 2 then 5 ^ 3 .......and adding result till 5^i < number.

Let we get that number has n number of zero then we are sure that the number has at least n number of 2 and n number of 5. What we have to do is to just remove n number of 2 and 5 from given number and keep track of last digit , till we get the answer.
here is the working code
int main ()
{
int Num2, Num5;
int Ldigit = 1, tmp;
int Num, NumZero = 0, i;
scanf ( " %d", &Num );
for ( i = 1; ;i++ )
{
tmp = pow ( 5, i );
if ( tmp > Num )
break;
NumZero += Num / tmp;
}
Num2 = Num5 = NumZero;
for ( i = 2; i <= Num; i++ )
{
tmp = i;

while ( !(tmp % 2) && (Num2>0) )
{
tmp /= 2;
Num2--;
}
while ( !(tmp % 5) && (Num5>0) )
{
tmp /= 5;
Num5--;
}

Ldigit *= tmp;
Ldigit %= 10;
}
printf ( " Last Digt = %d\n", Ldigit );
return 0;
}

Tuesday, September 2, 2008

Integer Overflow

Yesterday i was working on a problem where we have to check a number is whether prime or not , for that i gone through two famous prime testing algorithm , but i was getting wrong answer , i was trying hard but nothing worked , then i searched on internet , where i found very interesting thing.

It is well known that when we have to find the value of a raise to power n , we can calculate it in O ( log n ) time , we can apply same logic when we have to get a * b, what ever we did to n same thing we do to b here. This was the culprit as when i was calculating a * b it was going beyond integer range ( Actually we apply this logic when we have to found modulo of a * b otherwise it is of no use because it will grow beyond longest integer value ).

But above logic won't work if 2 * a goes beyond longest integer range, java provide us with facility to create our own custom integer .

Saturday, August 30, 2008

Gossiper and Me :(

Normally i like to talk a lot , here came the problem. I found a problem Gossiper , u can refer here https://www.spoj.pl/problems/GOSSIPER/ , i had to spent a lot of time on it. I coded it twice but nothing was working, i was thinking continuously about it in such an instant that i was not able to concentrate on other things , i had some intuition about it but i was not getting a clear picture about how to implement.

So i was just hapless , just before dinner i talked to divyendu who solved this problem then i got a glimpse of where to go. I just coded it from scratch and finally it worked it got accepted but it took 1.32 sec , i know merely less than one and half sec. but from programming point of view it is quite high. Best solution of this problem took merely 0.02 sec ( amazing ) but he took more space almost 32 MB while i took 20 MB.

Our well known saying apply here also , to get something we have to sacrifice something. For better time we have to consume a more space and vice versa .My rank is getting better but i am still in beginning stage , i have a long way to go .................

Tuesday, August 26, 2008

Mataki Fhod in IIIT Hyderabad

What the moment that was , i am spending some of best moment of my life in IIIT , i never imagined that i will be part of such an extraordinary place. Two days back we celebrate Krishana Janamastmi here , here we had Matki Phod event which i saw in TV only , as against last year , i took participate this year , it was an amazing experiance.

Last week we had fresher party for our new batches ,another wonderful time . First time in my life i took responsibility for an event , our team did well to make it into successful event. Students here are so exceptional that if one face this crowd then he can face any one anywhere. Hats off to them.

When i see me now as against last year or back , i am getting more and more confident , thanx to shushanta ( my best friend and ex part time student ) for creating a love for programming, it is one of the best human created thing , but some time it gives a lot of frustration as well when i dont get what i wish to.

Wednesday, August 20, 2008

APS back with a Bang!!!!!!!

APS ( Advance Problem Solving ), it is a fearful word to almost all PG student who come here and take this course. It is completely programming oriented subject and students have to go through rigorous schedule , two labs of two hours in a week where we have to solve some programming puzzle on the spot and if we are lucky ( most of times ) we get extra time after lab also.

In short , it consumes entire day , then come a wonderful assignment which takes a lot of time and give immense pressure , but the beauty of this course is that students unintentionally become good programmer, he start to think logically.

It is this course which taught me real programming , but since last week i have become a bit lazy that's why my rank is getting better but the pace is a point of worry.

Today was special as one of wrestler from our country won bronze , it was very pleasant surprise and second indian cricket team anyhow manage to won , but what matter is they won. In this olympic one thing that surpise me most is medal tally , china with 46 gold today is way ahead of USA with 25 odd gold out of which 8 won by its legendry swimmer.

is this the end of monoply of USA in olympic game . Lets see