Sieve of Eratosthenes

•February 7, 2010 • Leave a Comment

This is a simple and ancient algorithm for finding all prime numbers up to a given number, say n. Although it is a very, very old algorithm, it works fairly efficiently for numbers under 10 million. As the name suggests, this algorithm was created by a Greek mathematician by the name of Eratosthenes…

The following is the algorithm he suggested:

Simply make a list of consecutive numbers from 2 up to the number n. Now, take each number from the front of the list (first 2, then 3 and so on) and remove the multiples of each of these numbers from the rest of the list starting from the square of the number.  At the end of this procedure, all remaining numbers are prime…

Therefore, in essence, we keep removing elements over and over using one number at a time to choose the numbers that must be removed.

Here’s a working version of the algorithm. Say we want all prime numbers from 1 to 20.

Step 1: Make a list of all numbers from 2 to 20

2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20

Step 2: Take the first number i.e. 2 and remove all its multiples from the list starting from 4.

2  3  5  7  9  11  13  15  17  19

Step 2: Take the next number (2nd number) i.e. 3 and remove all its multiples from the list starting from 9

2  3  5  7  11  13  17  19

Step 3: Take the next number (3rd number) i.e. 5 and remove all its multiples from the list starting from 25. But, since 25 is greater than our n = 20, the process stops at this step.

Therefore, our final list of prime numbers is:

2  3  5  7  11  13  17  19

And yay! that’s the right answer… and computationally easy and efficient!

The Melody of Life

•February 6, 2010 • Leave a Comment

Sometimes life goes by too fast and it’s not the fault of the clock ticking on the wall. It is not even the fault of your busy schedule. It is your fault… the fault of the person who has lost himself/herself in the noise of the world and can no more hear the melody of life. An analogy to explain this would be a person who focuses so much on the lyrics of a song that he can’t hear the tune…

Life’s too short and beautiful moments, relations and experiences must be kept close to the heart so one doesn’t lose sight of what is really important in life. It doesn’t matter where you are ten years from now. It’s the memories you hold in your heart, the friends that have stayed by your side and the experiences that make you who you are that matter.

Of course, one can’t ignore the noise of the world, but one must not lose the melody of life under any circumstances. Today, I know that I will do my best to hold on to the moments, friends and experiences that bring joy to me…

Breathing.. Barely.

•February 1, 2010 • Leave a Comment

I’ve managed to get sick again. Wheezing, coughing and wheezing again. It sucks when one can’t breathe because isn’t breathing everyone’s birth right?! Meh… I guess it might be Spring making everything worse…

allergies + sickness = painful

This is when I wish my family was here…

What My Heart Wants

•January 28, 2010 • 1 Comment

I’ve recently worked very hard not just at work and school but also at ‘living’ my life. I’ve learnt that if I was given complete freedom from the chains of society and allowed to do what my heart wants, I would choose one of the following:

- Go backpacking through India. It would allow me to learn and talk to people from different belief systems and see my country from the eyes of a stranger.
- Stay on campus with my friends for an entire semester without having to attend classes and appreciate life and friends.

Unfortunately, people are supposed to either be in school (college) or work. To do anything else is referred to as slacking and signifies the presence of laziness. But I don’t want to look back on life when I’m 50 or 60 and have nothing but books, files and meetings to look back on. I want to live my life… is it too much to ask for?

Setting Up An Icon for Iphone Apps

•January 25, 2010 • Leave a Comment

So, I’ve been working on some small iphone applications for a while. Today, another computer science major asked me how you set up the icon and I figured it’s blog-worthy.

I take it for granted that you are familiar with the files that a new project in xcode holds. Basically, once you open your project using xcode, the following are the steps you need to take:

- Name your icon – icon.png and copy it/move it to the Resources folder for your project which shows up on the left-most area of the development environment.

- Now, open the info.plist file for your project which should be within “Classes” for your project. Somewhere down the list on info.plist, you will see icon… set the value of this key to the name of your icon i.e. icon.png.

Ta da! It’s done!

Squaring Numbers Close to 100

•January 23, 2010 • Leave a Comment

So, here’s another math trick and this one may be a little less intuitive to follow. It’s about squaring numbers close to 100 without that piece of machine called the calculator.

Example: Squaring 108 i.e. Calculating (108) * (108)

Now, we know that 108 differs from 100 by a +8. We make use of this and add this 8 to the number we have.

108+8 = 116

Now, we leave 116 as the left most digits of the answer and take the square of just 8. We get  8*8 = 64.

Therefore, our answer is : 11664

And voila, your calculator agrees!

Damn, I love math tricks.

Jan 19th, A Horrible Tuesday

•January 19, 2010 • Leave a Comment

I just need to figure out why it’s so hard for people to understand where I’m coming from regarding certain things in life. Would you talk to someone who brings you down and keeps telling you that you’re not going to  be like every other person around you? I think not. So, why do I have to make an effort against my own will and see such people when they aren’t really helping me move forward. They just stop me in my way and then instead of running at my pace, I sit down (metaphorically speaking).

Meh, not happy. Hopefully today is going to be a good day and I’m going to be in my happy-medium again.

In The Lap of History

•January 18, 2010 • Leave a Comment

If you haven’t heard anything by Built to Spill yet, in my humble opinion, you need to leave my blog and type “youtube.com” in your browser bar. These lines are from a song called Life’s A Dream…

Destiny’s vulgar so I might as well resist
Out of the darkness and all of the secrets still exist
Finally decided, and by decide I mean accept,
I don’t need all those other chances I won’t get.

To me, this song is about coming to terms with life and being at one with your universe. To know that no matter what, you exist and always will… even if it is just as a memory, a part of a family tree or a legend. You will leave your footprints in the sand of time and no amount of clicking of the clock can take that away from you. You have shared time with many other souls on this planet and have left your mark on the map of life. So, no matter how down or useless you feel in this moment and no matter how many secrets you die with, remember that you don’t need any of the chances that others got… your life, your decisions and your path in life is enough to hold you in the lap of history forever…

Doorstep of Adulthood

•December 23, 2009 • Leave a Comment

Life goes by too fast… too fast all the time. And while it’s passing us all by, we experience moments of realization that pass us by equally fast. This moment right here is one of them for me. I am in India and this visit is helping me reconnect with my past. Whether it be the people I’ve met as a little kid and forgotten, the voices that used to once comfort me or just the sounds and smells of familiar places I haven’t been to in a while.

I’m not the 7 year old who was pampered by my parents professional contacts anymore. Instead, I’m now the 21 year old they come up to, shake hands with and have a conversation with only realizing that they have met me before after my parents introduce us later in the evening. I’m not the 5 year old they hand candy to, but the 21 year old they discuss serious topics with.

I’m on the doorstep of adulthood but it’s only scary when I forget that I’ll always be a kid for all the adults I was close to when I actually was a kid.

Failed

•December 4, 2009 • Leave a Comment

I failed… yes, Ekshita failed.