Tuesday, December 25, 2012

Books I read in 2012

So it's December 25th(happy winter solstice), and another year has gone bye, wasted. Well mostly wasted, one thing I've done this year is that I've read, quiet a few books. 18, in fact, that I can remember. Of course if you add the technical books, which I never read cover to cover -  only read the parts I'm interested in, and books which I started and then didn't finish the number rises, but I'll leave those books out. Here is the list of books I've read this year -

Of these, the two by Peter F. Hamilton were the best, for me at least. Specially Pandoras Star. The prequel to the Void Trilogy, which I absolutely loved.

As for 2013, I'd love to read the two books left in the Commonwealth Universe - Judas Unchained(sequel to Pandora's Star) and Misspent Youth(heh, I think if I ever end up writing a autobiography I'll use this title). Also, Prelude to the Foundation and Forward the Foundation, by Isaac Asimov, which will complete the Foundation series for me, and quiet possibly the Robot books too(except for Bicentennial Man).

If you came here hoping for a review or at least a skinny on a few books, then go here ;p

Saturday, December 22, 2012


We are all made of stardust. Every single atom in our body, every singe atom of everything around us was once part of a star, a star that died in the most spectacular of explosions.
That is a wonderful idea isn't it. Well it's not just an idea, but a fact.
I first came across this about two years ago when I first started watching Discovery Science and fell in love with the idea that I was once part of a star, or maybe even more than one star.
If anyone says that science is boring & without any beauty, then they clearly don't know that the atoms of their body were forged in the heart of a star. If you are among those people, or even if you're not, then you should watch Wonders of the Universe, presented by Prof. Brian Cox, especially episode 2 where he talks about this phenomena, and does so very poetically.

Saturday, March 17, 2012

Collatz madness!

I think every regular, or even semi regular xkcd reader is familiar with the Collatz Conjecture

I have always found this problem intriguing, and Project Euler problem 14 did give me an excuse to codify it, but I just ran though the way I'd go about it in my head, decided the best way to do that was to use a graph, and the left it at that(didn't want to implement a graph in python, or for that matter in any language - procrastination strikes yet again!).

After a while I kinda forgot about this problem, but then it came back in the form of a homework problem in the Udacity course CS101 and a lot of the students raised a storm in the forums, some were confused, some pissed that an open problem was put in the homework for a starter course.

Inspired by a forum post I decided to write a program that finds all the collatz numbers between 1...n. Though it didn't end up doing that, it did something which I think was far more interesting and fun.

What the code did was, with an initial value of 1 already in the list, it would calculate the collatz sequence for the number 1 larger than the previous highest in the list, and stop when it finds a number already in the list, add those to the main list & sort. Then after a predetermined amount of time, it would stop the loop & store the data in a text file.

Here is the loop that does all the work -
while time.time()<=end_time:
    temp_list = []
    i = collatz_sequence[-1]+1
    while i!=1:
        if i%2:
            i = 3*i+1
            i = i/2
        if i in collatz_sequence:
    collatz_sequence = collatz_sequence + temp_list
You can take a look at the entire code here.

The first time I ran the program, I let it run for 2 hours & got astounding results. It returned a list of 358105 numbers, with the largest being a mammoth 366 digits at ~5.56*10365! The file was almost 51mb in size, with 10754 pages in open office at a font size of 10 - it wouldn't open in gedit.

The second time I let it run for 6 hours and got a list of 589089 numbers, in a file of size over 122mb and 25841pages, with the largest number being 522 digits long at ~7.15*10521.

522 freaking digits!

This was no serious attempt to understand or solve(lol) the Collatz Conjecture, just having a bit of fun with code, because the internet was out. But still, it is a testament to the ability of Python to handle large numbers.

Edit - This is a slightly better Collatz program, and solves the Project Euler problem mentioned earlier - collatz_cycle.py

Tuesday, November 22, 2011

The Invention of Flanguage

Flanguage is a version of English in which you make portmanteau of fuck & pretty much any word you can for added effect & brevity. That does not mean you do that to every other word in a sentence. You have to choose the right word(s) in the sentence to flanguagize for flanguage to have the best effect.
Some popular flanguagized words are

  • Fawsome - fucking awesome
  • Fuggly - fucking ugly
  • Fungry - fucking hungry

Fungry is actually the first flanguagized word.
It all happened on a road trip with 3 friends - Aditya(the first user of Flanguage), Ravi & Rakshit.
In retrospect, frip embodied flanguage & was the perfect frip to come up with it. A little background info is in order.
There was confusion as to where we were going & what we were gonna do there. We got lost quiet a few times, misjudged the time it would take to get to place, and after finally reaching there found it to be a huge letdown, got into a couple of tiffs with the locals, got into a heated debate about religion & spent a majority of the time driving around.
Even before the frip started there were signs that this trip wasn't going to be something F.
The plan was to take a bus to Jaipur after midnight & link up with Rakshit and then drive to our destination. So on Friday, 13th of August I left my house, on the edge of East Delhi at about 6pm, to Adi's place, in Gurgaon - beyond west Delhi, to meet up with him & Ravi. Luckily the metro got me there in an hour. But then what should have been a comfortable sub 30 minute commute from the metro station to Adi's house turned into a harrowing 2 hour adventure hopping the infamous Gurgaon shared autos.
But that was nothing compared to what happened to Ravi. He was home visiting his parents & planned to take the afternoon train into Gurgaon. Yeah right. All the trains were full, jam packed & he ended up riding on the roof of one.
Finally time came to leave & we got to the bus station. Yeah, we weren't going anywhere, all the buses were full. No space on the roofs even! Why would there be any space on any bus, the hindu festival of Raksha Bandhan was on the 14th & people were rushing back to their homes.
Luckily for us Adi called his dad & asked for the car and we were on our way to Jaipur.
So this was the trip during which Flanguage was invented.
So, on the morning of the 14th, I don't know the exact time - all I remember was that it was really early but the sun was up; we had just hit some town - don't remember which one; Ravi was sleeping in the back seat. Adi looks at me & says "I'm fungry, oh I meant fucking hungry". And that is when Flanguage was invented.
My contribution - Among other things, I coined the term flanguage :D
tl;dr : Invented a fawsome version of English called Flanguage.

Saturday, November 19, 2011

Back again & kicking procrastination by re-learning programming by solving Project Euler problems

It's been almost a year since my last post. What have I been doing all this time? Procrastinating!
If there was a contest for the laziest person in the world right now, I'd win hands down.
So while I was whiling away my time yet again, I came across this article, which I had read a few months ago, by Peter Norvig on learning programming in which he contends that it would take 10 years to properly learn programming. That reminded me to the article that had linked me to Norvig's article, on gamedev.net - Become a Good Programmer in Six Really Hard Steps.
I reread both of them. While reading the gamedev.net article I realized that I should have been doing all the things the article says, instead of procrastinating. Then it hit me. If I keep this up, I'll never accomplish any of the goals I had set for myself. This lazy streak has to end.
Now, where to begin. This step has been my achilles heel. I'm good at planning, but the problem is that I plan too far ahead & get lost in the cool stuff I'll be doing in the months or years to come. The here & now gets neglected. Then because I'm also good at refactoring, as time goes by, instead of feeling guilt or pressure I just refactor my goals, plans & I'm all set day dreaming about the future I might have if I stopped day dreaming.
So I decided to start small. I remembered about Project Euler - a site with interesting programming puzzles. It's not much but I had been going back to the site every couple of months with the intention of getting started on the problems but always found some excuse to not start straight away.
Not this time. I initially thought of working on the problems in either C or javascript, but eventually decided to use Python, as I have had a Python book lying around for over a year & never bothered to read it.
tl;dr : Was lazy, decided to stop fucking around & get started on Project Euler problems.
I created an account & decided to tackle the problems in decreasing order of the number  people that have solved them, i.e from the easiest to the hardest.
Solved 4 problems last night, rather this morning.
Problem 1 : If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.

Simple enough. Add all multiples of 3 below 1000, then add to that all multiples of 5 below 1000 except those which are also multiples of 3.
num = 0
i = 3
while i<1000:
num += i
i += 3
i = 5
while i<1000:
num += i
i += 5
print num
Answer : 233168

Next up, Problem 2Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

This wasn't that hard either. I just started with 1 & 1 as the first two terms, this way I would have every 3rd term as even.

total = 0
term_n1 = 1
term_n2 =1
term_n = 0
i = 3
while term_n<4000000:
term_n = term_n1 + term_n2
term_n2 = term_n1
term_n1 = term_n
if i==3:
total += term_n
i = 0
i += 1
print total
Answer : 4613732

Problem 6The sum of the squares of the first ten natural numbers is,

12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

Easier than the last one.

 import math
sum_of_sq = 0sq_of_sum = 0for num in range(1,101): sum_of_sq += pow(num,2) sq_of_sum += numsq_of_sum = pow(sq_of_sum,2)diff = sq_of_sum - sum_of_sqprint diff
Answer : 25164150

Problem 52520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Now this one caused me a little bit of a problem. My own mistake though, tried to be too smart. I had determined that we only had to check for multiples of 11, 13, 14, 16, 17, 18, 19 & 20 to get the answer. Then I noticed that all of them would have to be multiples of 20 & from that I somehow ended up with 11, 13, 7, 4, 17, 9, 19. Which didn't give the right answer so I went back to my old list & it worked perfectly.
But the code needs to be optimized. It took 5-6 seconds to run, which for such a small problem is pretty unacceptable.
def high_mul(x, y):
i = x
j = y
while i!=j:
if i<j:
i += x
elif i>j:
j += y
return i

def func(a, b):
if (a == b):
return a
else :
return(high_mul(a, b))

numbers = [11, 13, 14, 16, 17, 18, 19, 20]
solution = 1
for num in numbers:
solution = func(solution, num)
print solution
Answer : 232792560

  tl;dr2 : Wrote some code.

This is my Project Euler badge. Right now it's just at 4 solved, hopefully I can get it higher in the coming weeks.


Monday, January 10, 2011

Gotta stop buying books & start READING them!!

I just realized today that I've bought a bunch of books over the last couple of months & have just read one of 'em. Ten books, without counting the plethora of technical books that I've bought, have been bought & just one read. That freakin' weird. I love reading books, or at least I used to, thats why I buy 'em. Guess I've become too lazy now to even read.
Here's the list of books -

  1. Death Watch, by Jim Kelly

  2. The Emperor's Codes, by Michael Smith

  3. The Bible Code, by Michael Drosnin (Bought it at the same time I bought The Emperor's Codes & the *Code* in the title got me intrigued>

  4. Meta Math - The Quest for Omega, by Gregory Chaitin

  5. Selected works of Homer

  6. Perfume - The Story of a Murderer, by Patrick Süskind

  7. Code Breaking : A History and Exploration, by Rudolf Kippenhahn

  8. The Republic, by Plato

  9. Learn German With a Story : Welcome to Switzerland, by Stephan Wiesner

  10. The Moral Landscape : How Science can Determine Human Values, by Sam Harris

  11. So there you go, 10 books & only one - The Emperor's Codes has been read. Its a shame really. Oh, & I've already pre-ordered another -

  12. Reality is Broken, by Jane McGonigal

Guess I've got a lot of reading to do, wonder which book I should start with. Any comments?

Thursday, December 2, 2010

A Break from Eternal Lands to boost Productivity

I left my about a week and a half ago(post here). I was excited about finally having time to start working on my own projects, mainly the very clichéd-ly code-named Project X.

After a week work done = ZERO!

I saw a pattern in my daily routine that hampered pretty much all other daily activities - playing that wretchedly addictive MMORPG Eternal Lands. So on monday night, while in the middle of playing I suddenly announced to a friend that I'm quitting for a while & abruptly logged off.

Sadly, 60 hours since taking a break from MMORPG'ING productivity still remains ZILCH! I'm still in withdrawal mode. I thought how hard could it be. I left facebook over 2 months ago & haven't had any problems. The 27 hour internet outage did help - long over due laundry was done during that time and it kept me away from the computer for most of those 27 hours so my eyes got some much needed rest.

Hoping that the withdrawal ends today & I get some work done