Saturday, 28 July 2012

Going to College and C Programming

The last two weeks have been pretty intense. I was moving out of my house and into a college for the first time in my life. The settling in period was quite hectic and ... well ... unsettling.
I am right now in a college hostel room in the National Institute of Technology (NIT), Trichy in Tamil Nadu, India. There were insane amounts of stuff to think about, buy and drag across the campus into my new residence (No, I cannot and never will call it home.)

After a week of classes, things are finally starting to feel normal.

On a related note, I'm learning C programming in my computer science class (one of the 8 subjects I have to take during the first year of engineering.) and I'm finding (to my delight) that C is extremely easy to learn. There is an excellent reason for this though. Back when I was in Year 10, during my month long holiday in December, I had hours of endless fun self learning Java Programming. I never thought at that time that those hours of endless fun would translate into a general ability to pick up within days almost any C related programming language.  (Like Python, C++, Java ...).

I got an assignment to write down/create an interesting program. The only requirement our professor set was that I (the programmer) had to be able to explain exactly how the program worked if asked to do so. So, I decided to write a program which generated prime numbers up to a certain user specified upper limit. I thought it was a good place to start as it uses almost all the basic concepts of C programming.

But the program felt a little dull even for something related to prime numbers. So I decided to make it really interesting. I'm sure the geeks among my readers will appreciate much of the code, especially  the variable names.


#include <stdio.h>
#include <stdlib.h>
int gandalf_the_primechecker(int charles_CABBAGE);
int main()
{
    printf("This is a program I wrote which spews forth all prime numbers that fall   below an upper limit.\n");
    int charles_CABBAGE;
    int ashwin_limit;  //The upper limit. I call it the "ashwin_limit"
    printf("\nI now demand that you give me an upper limit! ");
    scanf("%d",&ashwin_limit);
 
    for(charles_CABBAGE=2;charles_CABBAGE<ashwin_limit;charles_CABBAGE++)
    {
        if(charles_CABBAGE==2 || charles_CABBAGE==3 || gandalf_the_primechecker(charles_CABBAGE))
        {
            printf("\n%d\n",charles_CABBAGE);
         
        }
        else
        {
            printf(".");
        }
    }
    printf("That's all folks! Bye for now!\n");
    printf("\nThe meaning of life is 42.\n");
    printf("\nSo follow the white rabbit.");
    system("PAUSE");
    return 0;
}
int gandalf_the_primechecker(int charles_CABBAGE)
{
    int Middle_Earth;//The midpoint between the ashwin_limit (upper limit) and zero.
    Middle_Earth = charles_CABBAGE/2;
    int The_Shire;
    The_Shire = 2;
    while(The_Shire <=Middle_Earth)
    {
        if(charles_CABBAGE%The_Shire != 0 && The_Shire==Middle_Earth)
        {
            return 1;
        }
        else if(charles_CABBAGE%The_Shire !=0)
        {
            The_Shire++;
        }
        else if(charles_CABBAGE%The_Shire ==0)
        {
            return 0;
            break;
        }
    }
}



Monday, 16 July 2012

The Chaos Walking Trilogy


Here is what I said about fiction from a previous post:

"Another mark of a good story is how it draws you in. Many books (like Eragon and Harry Potter) talk about worlds in which, deep inside, everyone wishes to live in. Reading them makes me want to live the book so badly that sometimes I can't help laying awake at night thinking of all the cool, amazing things I would do if I were in the place of the protagonist."
No book I've ever read so far does this more perfectly than the Chaos Walking Trilogy.

I read the three books in this trilogy with a level of concentration that had eluded me for over a year. I've never come across a book with such endearingly real characters and such a realistic and deeply moving plot. The author manages to keep the plot complex and events unexpected without the use of unbelievable coincidences. I also found the whole concept of Noise and how the plot revolves around it incredibly original and creative. It's original enough that for the first time in many years I found it impossible predict the plot. A very worthwhile and enjoyable read.


Sunday, 15 July 2012

More about the Kindle touch Battery

I've made a few observations that seem to clear up the issue. I was reading "The Demon Haunted World" by Carl Sagan when I noticed that the value of the Kindle Touch's location seems jump forward quite a lot more than usual. I have no idea if there is a formula to convert between actual page flips and kindle locations. If there is one it probably varies with each book. So this paragraph I wrote in my earlier post is wrong.

Considering the fact that an average book like "Brave New World" by Aldous Huxley has 3993 locations (that's the kindle's substitute for a page number) which translates to about 2000 page flips and that a person like me can finish a paperback edition of a book like that (If I find the book exciting and therefore impossible to put down) in about 8 hours or so ( I read quite a bit faster that 250 words per minute) I could probably drain the Kindle's battery with one night of reading! 
It is evident that the 3993 page locations are not equivalent to 2000 page flips. It's most probably a whole lot less since I've seen the location value jump by 5 or 10. So I probably can't drain the battery with one night of reading. However the rest of my calculations still hold.

I did a quick search on the kindle forums and found that most people do use the estimate of 250 words per page to calculate actual page flips/numbers on the Kindle Touch. So for the average person with an average reading rate 1800 page flips do seem to be a reasonable estimate for the battery life (+ a bit more depending on discharge while not using the device).



So here's what I know for sure.

1. The Kindle Touch by amazon's estimate can last two months if used for half an hour per day.

2. If used continuously it can last for at least thirty hours. I reason that it may last more if used continuously. The lithium ion battery used in the Kindle Touch will discharge slowly over time if left unused. Amazon must have calculated the two months battery life taking into account this self discharge.

On the whole the one week of usage I get seems reasonable since I use the device for much longer than half an hour a day.

I wonder if I should use the device for a timed period of half an hour daily for a month as an experiment just for the fun of it...

Biscuits and tea with William: YouTuber and Maths-enthusiast Vihart on reaching y...

Follow This LInk to read the rest of the post--->Biscuits and tea with William: YouTuber and Maths-enthusiast Vihart on reaching y...: In this video Vihart discusses a surprisingly relevant, to the internet today, piece of writing from the 70s in a video that should be inte...

Couldn't agree more. Reminds me a bit of this xkcd comic.

(Note: Finding xkcd comics that are relevant to every situation you come across is the first sign of xkcd addiction.)

Enabled Disqus Comments in my Blog

The default comment space for blogger does not have that many features. So I've decided to add the Disqus commenting feature to my blog. This should clean things up a bit.

All my blogposts currently show zero comments because it'll take a while to import all the comments. 

Thursday, 12 July 2012

Spotted a Death Note Reference in Harry Potter and the Methods of Rationality

One thing I've noticed is that HPMoR is full of geeky references to famous movies/books/anime that people like me are interested in. It's of the pleasures of reading the book after you've been exposed to the geek culture for a long time. Those references pop out of the page and make the experience of reading a book quite enjoyable. For example look at this little section from chapter 24. There is a spoiler below but I've managed to copy it so that it reveals as little of the plot line as possible.

SPOILER BELOW!

Father had once taken him to see a play called The Tragedy of Light, about this incredibly clever Slytherin named Light who'd set out to purify the world of evil using an ancient ring that could kill anyone whose name and face he knew, and who'd been opposed by another incredibly clever Slytherin, a villain named Lawliet, who'd worn a disguise to conceal his true face; and Draco had shouted and cheered at all the right parts, especially in the middle; and then the play had ended sadly and Draco had been hugely disappointed and Father had gently pointed out that the word 'Tragedy' was right there in the title.
Afterward, Father had asked Draco if he understood why they had gone to see this play.
Draco had said it was to teach him to be as cunning as Light and Lawliet when he grew up.

I couldn't believe it at first! It's actually a Death Note reference! If you haven't seen this particular anime series before, I highly recommend it. It belongs to that class of "intellectual" anime like "Detective School Q" (Which is also awesome by the way) that really stimulates the brain.  

Wednesday, 11 July 2012

Exactly.

One of the many reasons Neil deGrasse Tyson is my favourite astrophysicist/science popularizer.

Tuesday, 10 July 2012

Harry Potter and the Methods of Rationality: A Review

I finally finished reading all 85 chapters in HPMoR. Although it is a work in progress it is still one of the best books I've ever read. Until now the books I thought most highly about were the books in the Chaos Walking Trilogy written by Patrick Ness. That book was always full of excitement. Every sentence made you more interested. Every sentence made you want to read the next.

HPMoR is better not just because of the excitement in its pages. It does have exciting chapters. There are many chapters where my pulse literally started racing. (Personally I think Chapters 51-61 and Chapters 79-85 were the most exciting.) HPMoR is better because of the amount of knowledge and inspiration it can impart. It has evolved into something more than just a piece of fanfiction. It's when I read stories like this that I realize how much strict copyright laws are stifling creativity. I wonder how many more excellent works of literary art we could have enjoyed if copyright restrictions didn't extend so long after the lives of the authors.

WARNING: THE REST OF THE POST PROBABLY CONTAINS MAJOR SPOILERS. READ ONLY IF YOU'RE OKAY WITH SPOILERS. 

I was particularly inspired by the thoughts expressed in chapter 45. Let me quote what is in my opinion one of the most beautiful thoughts I've ever seen expressed. It is so beautiful that even now as I read it to copy and paste, I feel goosebumps erupting all over my body. The kind that you often experience after  you stumble upon a heavenly piece of music.


Harry thought of the stars, the image that had almost held off the Dementor even without a Patronus. Only this time, Harry added the missing ingredient, he'd never truly seen it but he'd seen the pictures and the video. The Earth, blazing blue and white with reflected sunlight as it hung in space, amid the black void and the brilliant points of light. It belonged there, within that image, because it was what gave everything else its meaning. The Earth was what made the stars significant, made them more than uncontrolled fusion reactions, because it was Earth that would someday colonize the galaxy, and fulfill the promise of the night sky.
Would they still be plagued by Dementors, the children's children's children, the distant descendants of humankind as they strode from star to star? No. Of course not. The Dementors were only little nuisances, paling into nothingness in the light of that promise; not unkillable, not invincible, not even close. You had to put up with little nuisances, if you were one of the lucky and unlucky few to be born on Earth; on Ancient Earth, as it would be remembered someday. That too was part of what it meant to be alive, if you were one of the tiny handful of sentient beings born into the beginning of all things, before intelligent life had come fully into its power. That the much vaster future depended on what you did here, now, in the earliest days of dawn, when there was still so much darkness to be fought, and temporary nuisances like Dementors.
Mum and Dad, Hermione's friendship and Draco's journey, Neville and Seamus and Lavender and Dean, the blue sky and brilliant Sun and all bright things, the Earth, the stars, the promise, everything humanity was and everything it would become...
On the wand, Harry's fingers moved into their starting positions; he was ready, now, to think the right sort of warm and happy thought.
And Harry's eyes stared directly at that which lay beneath the tattered cloak, looked straight at that which had been named Dementor. The void, the emptiness, the hole in the universe, the absence of color and space, the open drain through which warmth poured out of the world.
The fear it exuded stole away all happy thoughts, its closeness drained your power and strength, its kiss would destroy everything that you were.
I know you now, Harry thought as his wand twitched once, twice, thrice and four times, as his fingers slid exactly the right distances, I comprehend your nature, you symbolize Death, through some law of magic you are a shadow that Death casts into the world.
And Death is not something I will ever embrace.
It is only a childish thing, that the human species has not yet outgrown.
And someday...
We'll get over it...
And people won't have to say goodbye any more...
The wand rose up and leveled straight at the Dementor.
"EXPECTO PATRONUM!"
There is also this little tidbit from the next chapter.

"I have a dream," said Harry's voice, "that one day sentient beings will be judged by the patterns of their minds, and not their color or their shape or the stuff they're made of, or who their parents were. Because if we can get along with crystal things someday, how silly would it be not to get along with Muggleborns, who are shaped like us, and think like us, as alike to us as peas in a pod? The crystal things wouldn't even be able to tell the difference. How impossible is it to imagine that the hatred poisoning Slytherin House would be worth taking with us to the stars? Every life is precious, everything that thinks and knows itself and doesn't want to die. Lily Potter's life was precious, and Narcissa Malfoy's life was precious, even though it's too late for them now, it was sad when they died. But there are other lives that are still alive to be fought for. Your life, and my life, and Hermione Granger's life, all the lives of Earth, and all the lives beyond, to be defended and protected, EXPECTO PATRONUM!"
And there was light.

I've had similar thoughts over the years but I could never have expressed it so beautifully and so elegantly. These are, in my opinion the best parts of he book. If you read the book and had to chose a single idea that you could remember forever and forget the rest of the book choose these.


I can't wait for Chapters 86-91 to be released.

Revised Thoughts on the Kindle Touch

It took me about 3.5 hours today morning to read "The Perks of Being a Wallflower" on my Kindle Touch. It had about 2600 Kindle Locations. And the battery didn't drain beyond 75%. So my theory about the Kindle Touch battery drain having a linear relationship with the page flips may be wrong. There are a few possibilities.

  1. Somehow, reading half an hour a day for two months doesn't equal reading for 30 hours continuously. Somehow if you read continuously the battery drains slower than expected.
  2. My guesses were wrong. Amazon used a different average reading rate to calculate battery drainage.
  3. A software update I did recently on the Kindle Touch might have solved a software issue that was draining the battery.

I intend to experiment a bit more with the device to single out the most likely factor.

Also, there is a very faint crackling/buzzing noise coming from the bottom of the device which I can only hear if I put my ear very close to the device. I think it's most likely source is the speakers. Perhaps there is a software issue that sends a constant stream of noise to the speakers. Perhaps there is a software bug which makes the Kindle forget to turn its speakers off when they're not being used. But the strange thing is that the battery appears to last longer after the update and the sound coming from the speakers have not gone away after the updates. So maybe that isn't an issue. I'm not really sure. But I think it would be a good idea for amazon to write in some code to turn off the speakers when they're not being used (if it really is an issue with the speakers). 

Thursday, 5 July 2012

Thoughts on The Kindle Touch

A few weeks ago I got myself a new Kindle Touch. Since I'm going off to college soon I thought it would be useful to get a device that eliminated the need to carry around huge heavy cartons of my substantial book collection. I must say that there is something mindblowing about the idea that it can carry around a library. It brings to mind this little comic from xkcd.
YES! I LOVE XKCD!
There's little to criticize about the device. It's perfect for reading, listening to music and light web browsing. There is however one area in which the device which fell short of my expectations: The battery life. So let the nitpicking begin. Amazon promises two months of reading time on a single charge of the battery. My first full charge however lasted for only about a week even with the wireless off! After browsing through pages and pages of amazon forums I discovered that the problem did not lay in the battery but in the fact that Amazon's estimates were a bit too optimistic. It says on their website that you can
"read for up to two months on a single charge with wireless off and a half hour of reading per day"
Being an incorrigible math nut, I decided to do a little calculation to get a more realistic figure on how long the Kindle touch battery will last. From Wikipedia I get that the average reading rate of an adult human in is from 250 to 300 words per day. I assumed that Amazon probably used this statistic to come up with their "half an hour of reading per day" estimate. Next  I counted the number of lines on a page in the kindle touch with the default font size. It's about 25. The Kindle displays about 10 words per line meaning that each page displays about 250 words on avearge (I don't think the closeness of this number to the average adult reading rate is a coincidence).

So I interpreted Amazon's "half an hour of reading time" as being equivalent to about 30 page flips (That seems awfully small I wonder if I'm wrong?). This should be a reasonable measure of battery drain because EInk screens only use up power when they refresh or change what's on the screen. They do not require power to maintain a particular image or some text. So now our two months of reading time dwindles down into about 30(1800 minutes) hours (assuming each month has thirty days)  of continuous reading time or about 1800 page flips. This explains why my first charge lasted only a week as I read about 4-5 hours per day. Do that for a week and you get about 30 hours of reading time.

Considering the fact that an average book like "Brave New World" by Aldous Huxley has 3993 locations (that's the kindle's substitute for a page number) which translates to about 2000 page flips and that a person like me can finish a paperback edition of a book like that (If I find the book exciting and therefore impossible to put down) in about 8 hours or so ( I read quite a bit faster that 250 words per minute) I could probably drain the Kindle's battery with one night of reading!

So I think that amazon should have quoted a more straightforward figure like "Thirty hours of continuous reading" or "1800 page flips" instead of "Two months". For more prolific readers the "two months" estimate is quite misleading. It's a bit like saying "Our laptop battery will last you two weeks with WiFi off and half an hour of usage per day" rather than "Our Laptop battery will last you 7 hours on a single charge." A misleading claim don't you think?