Monthly Archive for August, 2009

Project Euler : Finding The Largest Prime Factor Of A Given Number

The problem is this: Find the largest prime factor of a given number. One brute force way is to find a factor of the given number and then perform primality testing on the number. But the test to check if the number is prime or not is a costly operation if one does not have a set of all primes.

So there was a need for me to avoid the testing of a number for primality.

One interesting thing to be noticed is that the smallest factor of a number has to be prime. Suppose if it were not, then it implies that it can be written as a product of two smaller numbers which contradicts the hypothesis that the factor is the smallest factor.

So we can avoid the testing of primality by taking the smallest factor. But the problem requires us to determine the largest prime factor. The lergest prime factor can be recursively obtained by using the following:

public static long largestPrimeFactor(long n) {
    long prime = smallestPrimeFactor(n);
    return Math.max(prime, largestPrimeFactor(n/prime));
}

Where the smallest prime factor method returns the smallest factor of n.

One of the interesting things that I read while solving this problem was that after 3, all the prime numbers satisfy the general formula 6n-1, 6n+1. So the primes will be in the series :

6(1) – 1 = 5

6(1) + 1 = 7

6(2) – 1 = 11

6(2) + 1 = 13 …

In fact, primes after the number p belong to the series p# n + m, where p# is called the primorial. Look up the wiki entry to learn more.

Popularity: 5% [?]

Checking Off My Wishlist

Yesterday I was going through a few old posts when I came across a one wherein I had listed my wish list. I had planned to buy a few things after moving to Bangalore. This post is an update to that one.

Now that it is 3 months into post-graduation life at Bangalore, I have finally started ticking off things from my wish list. I had mentioned 4 back then -

  • A Dell XPS laptop
  • An iTouch to go with my Xperia
  • A domain name for myself
  • LastFm subscription

Here’s the update to the list -

  • I have a domain for myself now. Yay !! I have purchased this domain from justhost.com and have a hosting deal for the next two years.
  • I have subscribed at LastFm. Doubly Yay !! !! :) And I totally enjoyed their radio once again. God ! It feels so good listening to LastFm radio once again. Just to think of the number of songs available to me, chosen by LastFm makes me musically happy.

Things I have yet to do -

  • I have been given a Dell Latitude D630 from FICO and so have postponed any plans of XPS.
  • iTouch is the big question. Do I go for this gadget now or wait till a later time. I do not really need it right now, so probably I will put it off for some time.

Additionally -

  • I have an awesome bike – CBZ Extreme. Yipee. And I am totally in love with it. I have already driven ~1100 kms.

Additions to the wishlist -

  • Biking gear. This is of highest priority to me now. I need a pair of leather gloves, preferably leather jacket, a cool helmet. I am yet undecided on knee pads. :P

Hmm … Not much yet. Shall keep updating this list.

Popularity: 5% [?]

The Agony Of Having Data Protector

The company that I work for has provided me a Dell D630 Latitude. And since this is the only laptop I have, I use it for my personal purpose too. The laptop came with windows XP installed. Since I have never been a fan of Windows, I wanted to get back to ubuntu on my laptop.

This is where the problems started. Now the company is paranoid when it comes to security. They have installed an application called the Data Armor. This application keeps the hard disk encrypted at all times. In fact, when the laptop starts, the whole disk is encrypted and a password dialog box appears from Data Armor. At this point, if you do not know the password, you cannot decrypt the hard drive, thus ensuring the safety of the contents inside it.

When you log into Data Armor, the drive is decrypted, and the laptop boots again. This time though, the normal windows welcome screen appears. All the time that windows is operating, the Data Armor works in the background.

Now, I would like to install ubuntu using wubi on this laptop, but am not sure about a few issues. The biggest concern is that will installing ubuntu break or conflict with the Data Armor? I suppose the initial boot phase should be fine. After all, the hard disk is encrypted and Data Armor has no information whether the computer runs a windows or a linux. But then, once the reboot is done, will logging into ubuntu disrupt the functioning of Data Armor? Will it fail to maintain the encrypted state of the disk, thereby leading to a failure in the next boot up? Or will it gracefully allow the operation of ubuntu go on, and yet start up when logging into windows the next time?

So many questions to which I have no answers. I have tried googling around a bit but to no avail. I have only met with failure every time. In fact, I also tried querying the technical support guys at the company regarding this, but never got a satisfactory reply. A few question my need for ubuntu, reiterating that since my work does not require me to work on ubuntu, my official laptop should not contain the linux. A few nod to my possible explanations, but always remarking that even they are not sure of it. And then there are the few who don’t even know what wubi is!

So as it stands, I am yet to install ubuntu in my laptop. I will have to refine my search to get better results. Hopefully I succeed.

Popularity: 5% [?]

A Trip To Innovative Film City, Bangalore

After lots of if-and-buts, we finally managed to come up with an outing plan. The ‘we’ here stands for a group of new joinees at FICO, and the plan refers to Innovative Film City.

Now that we have a few bikes among us, we were eager to ride them on highways – Mysore highway being the prime road. Akshay had been to Innovative Film City earlier and he liked it. It was his idea that we drive to that place, some 44 km from our office. Amidst confusion, after many a persuasions, there were finally 9 people on 5 bikes. Akshay and his brother Swapnil on Pulsar 180, Vipin and his flat mate Naveen on another Pulsar 180, Sumeet and Lakke on the Hunk, Rohit and Nagori on Stunner and I on my CBZ Extreme.

Our journey stated at 11 on a sunny sunday morning. From Kodihalli, it was almost a straight road throughout. We encountered little traffic in the city, but were held up after crossing the city market. The narrow roads and the BMTC bus stop, with adjoining Big Bazaar slowed down the traffic to snails pace – not what we were hoping for. But once we cleared that area and crossed the Manipal Speciality Hospital, we sped off onto the state highway. There onwards it was an amazing drive with hardly any traffic. 5 bikes zooming through, the sun rays hardly having any effect and cool wind blowing across our face.

Before mid-day, we were at the film city. The entrance was awesomely, tempting us to venture inside. We walked down a flight of stairs to arrive at the ticket counter. Now this was the most confusing part for all of us.

Generally in India you have a price for entrance and then everything inside is free. But here, it was an entrance fee of just Rs. 50 and the rides being charged extra. So suppose you want to spend time at their artificial beach, you have to pay an additional 160. Judging by the time we had at our hand, we ended up purchasing tickets for a 4D show, Mirror Maze, Roller Skates, Roller Coaster and Beach. The complete cost was Rs. 590 per head. There were a few more options like Laser Tag, Dirt Biking, Go Karting, but we left the decision of buying tickets for these later, depending on the time left and the weather.

The 4D movie was a nice concept. You get to wear 3D goggles and then there are tools installed on seats to add the 4th dimension. So if you are in a place and flying across the clouds, you feel cool air blowing on your face. At one time we felt tickling sensation in our leg. Then there was the effect of the seats vibrating and all. All in all, it was worth the 80 rupees.

We next went to the Roller Skates. This was the most hilarious part. But for Lakke and Akshay, the rest had never tried skating before. So it was half an hour of watching people fall, and then get up to fall back again. I shall soon be uploading vidoes on facebook and youtube.

We next went to the Mirror Maze. This is an old concept of placing mirrors at angles and creating a small labyrinth so that you are lost. And since mirrors reflect and confuse your mind, you tend to go around and around in the same circle quite a few times before realizing it.

The roller coaster ride was a tad disappointing. It was too short to enjoy. Our ride completed in less than a minute’s time. I wouldn’t advise anyone to try that.

The best part of the whole day was the beach. Soft sands around a wave pool is a pleasing sight. We jumped into the pool and spent quite some time having fun with the waves and the floating air rings. Next we played the beach volleyball. Tired of jumping around in sand, we went swimming once again. This time, we played catches with a ball that Akshay had brought along. It was followed by a photo session. At 7 o’clock the security guard came to tell us off as the place was closing down.

We were amongst the last few to leave the film city. It was an enjoyable place, though I felt that the prices were a bit too steep. Rs. 100 for the roller coaster is not justified. And similarly for a few more rides. But the high prices does not really deter me from visiting that place again. Perhaps, after a few months I might go again.

Popularity: 55% [?]

Shoutcast Scrobbling In Last.fm

I was love with the last.fm radio until they made it a subscription only feature. And since I refuse to pay for something that I can get for free, I decided to give up the last fm radio and look for alternatives. I found the shoutcast radio and also the aol radio inbuilt in winamp. They were good and did the job for me.

But what I missed was the scrobbling of tracks. I wanted a plugin which could enable scrobbling of streaming music into my lastfm account.  I found none. This was until I stumbled across Streamripper.

Streamripper is a plugin for winamp which intercepts incoming stream and downloads them to the hard disk. It has a few options using which you can configure the location where the files are to be saved, the maximum size of the said folder, whether t he downloaded tracks are to be added to the current winamp playlist and so on.

So now to scrobble the tracks, all that needs to be done is this – start streaming some radio station. Streamripper detects an incoming stream and offers to save it. Start the interception. Now two streams get created – one for your winamp and the other for the ripper. You could continue listening to the station. But what I generally do is to switch to a different station for time being. Once the ripper has downloaded a few tracks and appended them to the playlist, I switch to the playlist created by the ripper. And obviously the lastfm scrobbler scrobbles the tracks played.

Occasionally, you might have to empty the contents of the folder where your tracks were being downloaded.

Happy streaming and scrobbling.

Popularity: 28% [?]

SC/ST Quota In The IIT's

My beliefs have always been firmly against any kind of quota when it comes to admission for higher education. And no argument has made me even consider my opinion. And the recent declaration by the Supreme Court that an IIT cannot disqualify a SC/ST student on academic ground (which can be done for a General category child) only confirms my view that the education system is run by opportunist politicians and not learned men. And I hate the politicians so much that I want their whole species eradicated. Not one of them, none of them are without flaw.

When we talk of an IIT, we are talking of institute which has global recognition and high esteem. People consider the IIT graduates as men of knowledge. These graduates should be able to stand out from the normal crowd and do wonders. And every graduate realizes, though seldom acknowledges, that the expectations are much more from him compared to any other person.

But what is so special about these IITs ? Why do the graduates have an edge compared to the rest. Is it because of the professors ? Is it because of the infrastructure ? Is it because of the close association among like minded people ? Can any body given a chance ot study in an IIT become just as good ?

No doubt the professors are good. Not all of them can express themselves clearly, and some times we student get a feeling that a professor is not upto a level required to teach in an IIT, but when you work under them on a project you realize that their excellence.

At IIT we have been provided very well when it comes to infrastructure. Well equipped labs provide students a hands on experience of what he listens to in the class. Also the alumni funding helps. We have round the clock electricity, high speed internet which rarely goes down. A library with huge collection of books, and not to forget our LAN with no dearth of material shared for everyone to download.

The IITs admit students based on their performance in the Joint Entrance Exam(JEE). It is no secret that serious aspirants prepare for years to write this test. The questions are though provoking (though people remark that they have been becoming easier are more mechanical over the years), and only the best get through. There are cut-0ff marks in each subject and then an overall minimum required to be ranked.  Only those with clear understanding of each of Physics, Chemistry and Mathematics make through. So the overall IQ of students in the campus is quite high. And you realize this when you talk to them. You can always find like minded people and develop your hobby. From personal experience, I have met many computer geeks and learned a lot more about programming from them than any professor or course.

The system thrives only because there are such intelligent students residing in the campus. Now when you talk about implementing a quota system, you are diluting this group of students. One important point to mention is that if the cutoff for general category is say 100 in 300, then it stands at hardly 50 for the SC/ST people. This is the difference between a quota and a general category student. And it pains me.

I was standing in IIT M 4 years ago and considering what might I get for a rank of 404 after having scored some 130. And then besides me was seated a category student, with some rank of 10K’s in general category but some 20′s in his respective quota, and he was confident of studying CSE at IIT K. I got IIT Kgp CSE for a much higher score than that fool. And yet the fool went to K and I got only Kgp. Who the hell can reason out on his behalf that his getting K, and mine only Kgp was justified ?

I’ve heard enough of this giving chance to under-proviledged people nonsense. I have been at IIT 4 years and let me tell you, a guy whose foundation is weak can never hope to compete with others, whatever you do for them. If you are so worried about providing these people better education, then propose a system in which their schooling is improved. Provide them better education at school level, so that they can compete with the general category students at JEE. Don’t you make a lousy excuse of having a quota to make them better qualified.

This is all a political gimmick. Last year we saw the worst of it when Arjun Singh increased the quota to 49%. Had he the power to cross the 50% limit, he would have had quota for almost 80%, leaving the general category students to fight for the remaining 20%.

We see the flaw in the system when IIT D decided to expel a few SC/ST students on the basis of poor performance. Of course, a student who does not understand simple mathematics, who is highly uneducated to clear the JEE on par with a general category student cannot be expected to perform on par with them in an IIT too. Just because he has been admitted into an IIT, through  a quota system, does not make him infinitely intelligent and capable in a day. He is still the incapable fool who could not clear the JEE exam.

But how did the IIT D matter end? Supreme Court intervened and has made a statement prohibiting IITs from expelling any SC/ST student on academic grounds.

So here we are. Thanks to our politicians, very soon we shall be seeing unqualified fools graduating out of the IITs.

If you are a supporter of the quota system, I beg you to just answer one question – A guy who does not understand mechanics, who could not pass the physics exam, how can he be expected to study Mechanical Engineering, understand concepts of stress and then graduate out to later design bridges or dams.

And for that matter, I am against quota in all fields. A person, who fails his biological exam, gets admitted into some reputed institute and goes on to become a surgeon (I am sure he will find quota at each step). God save me from such doctors.

No matter what argument you propose, the whole system of admitting students into higher education through a quota system is flawed. If you want these people to have better education, spend on their middle-school and high-school education. Provide them better opportunity to clear the 10th class and compete on par with the general category students in JEE. But a reservation of seats is a sorry excuse to get more votes.

Popularity: 14% [?]

Arbit

I just can’t wait for the new season of EPL to kick off. A community shield match between ManU and Chelsea promises to be an ideal start to the season. Though the english teams have lots a few great players to Real Madrid, its going to be an exciting season. More so because ManU doesn’t enjoy the complete dominance any more and Liverpool have been weakened by the departure of their players. Also the spending spree of Man City threatens to propel them into the top 4. With 6-7 teams being good, it should be fun.

Also the return of the God of Racing – Schumacher, has brought life to the dying 2009 season of F1. Just like that, there is buzz all around. Obviously people expect Michael to do some miracle and pull of a stunning victory. But his neck remains a worry, and he has asserted that unless given go by the doctors he shall not sit behind the wheel of F60 in valencia. I am keeping my fingers crossed.

I hope the break gets over soon and the season start. I am getting too impatient now. Gawd .. let the season just begin already.

Popularity: 2% [?]