Wednesday, December 28, 2005

Flow!

For the last few days, I've been busily coding away at USACO. For those who don't know, it's a place where they train you to do algorithmic programming of the kind that you see at TopCoder and so forth.

They follow a pretty effective technique of dividing their training pages into sections of increasing difficulty. As you finish solving one section, the next one becomes accessible. In about 4 days(I'm not very certain), I've done sections 2.3, 2.4, 2.5 and 3.1, which amounts to about 15 problems. That rate is almost devastating enough to be scary, because I've never coded so fast before. This leads me to conclude that I'm channeling the departed spirit of Edsger Dijkstra...

At any rate, I seem to have achieved what Mihaly Csikszentmihalyi(quite a mouthful, isn't it?) calls flow - a weird sort of state where I lose myself in code and algorithms, time ceases to have any meaning and my productivity increases tenfold. Like Csikszentmihalyi says in his books, it's an incredibly fulfilling state of mind. I'm tempted to say that there's this undercurrent of joy which pervades my being, but that isn't exactly it - it's more like nothing else in the universe matters other than the problem I'm working on and the act of solving it. It's a bit like being in a dream state, where things keep on happening all around you, but you don't seem to care very much, because all your attention is focused on just one thing.

If you haven't figured it out yet, I'm going to be chattering merrily on this subject for the remainder of this post. It's not particularly technical, though the stuff that I was doing was technical. I'll mostly talk about what it felt like. That should be enough to satisfy the people who like that human-interest stuff(as if writing code weren't a uniquely human activity!).

Interestingly enough, as I write this, I'm also chatting with Sagar, trying to explain the logic for a certain problem I was doing last night. The problem is section 2.5's Stringsobits, if anyone wants to know. I gave him the problem statement last night, and he got pretty interested(Sag, good to know the engineer in you still lives!). He tried a brute force algorithm, but of course, the constraints wouldn't allow that, otherwise I would have pulled it off in about 3 minutes...

I figured it out at around 2:30 AM last night. I was practically possessed - I had to solve that problem, and I was on the verge of seeing the pattern for so long that I knew I wouldn't be able to sleep until I had it. When I did see it, I was practically on cloud nine - I would have jumped up and down for joy if it wouldn't have woken people up...Frankly, it was the only problem in section 2.5 that I really found hard, and I wound up that section this morning with the last one I had left(Prime Cryptarithm), which turned out to be incredibly simple.

One of the things that used to happen to me earlier(like about a week ago), was that when I wrote code to solve a particular problem, I couldn't bring myself to like all of it equally. I'm not sure 'like' is the word I want, but it's the closest I can get. There's the stuff that really solves the problem, and the other stuff that's just helping out - I/O, formatting, parsing and all that. During the last few days, that distinction just went away. I became indifferent to the code I wrote, in a sense. Amazingly, the quality of my code skyrocketed, and I got more things right the first time than before. I can look back at my code now and love its elegance, but when I wrote it, I didn't have the same kind of emotional response I used to have. The feeling was a sort of 'smoothness' - the kind of feeling you might get on a boat cutting through the water, with wind ruffling your hair, and no troubles on your mind. In other words, my mind was flowing. No resistance - just ceaseless motion.

And if any fellow computer engineers think that writing code doesn't elicit an emotional response, I recommend they rethink their choice of career.

I've finally decided to stop and relax for a bit. Might as well enjoy this nice feeling of fulfillment in this excellent weather. This is what relaxation should feel like.

For all those people out there who talk about having a sense of proportion, here's a bit of advice - Don't. It's all very well for the little things that don't matter much to you, but for the work that you really care about, throw out any smidgen of an iota of a scintilla of a suggestion of a limit. There ain't no such thing.

In an interesting coincidence, while I was musing about having a sense of proportion, who should come along but Paul Graham, with another masterful essay on procrastination. Relates well to my thoughts on the subject.



PS: I'm not sure if I mentioned this before, but the pigeon nesting outside the kitchen window finally hatched her egg. Junior has grown incredibly fast. He's now at the point where his parents can't sit on him any longer - something they spent an inordinate amount of time doing earlier. I still haven't made up my mind whether they were protecting him from the cold or if they were just too dumb to figure out that you don't sit on the chap that comes out of the egg...

Thursday, December 22, 2005

Brrr - Of cold winters and civil war

The city has gotten rather cold lately. Yesterday was Mumbai's coldest day in over half a century, with temperatures hitting 11 degrees Celsius. By Mumbai standards, that's as good as 11 below zero.

December 21st, 2005 - A day that shall forever live in infamy! After begrudgingly rendering faithful service for the last few weeks, my nose has trechearously chosen this fateful day to declare war on the rest of me. In a bold move, it has besieged my sinuses, squeezing my air supply lines to a trickle. The frontline troops in my throat are fighting valiantly, but suffering grievous losses. Major offensives by elite Nasal Mucus Commandos are met with devastating force, but the situation is still unstable, resulting in a sore throat and blocked sinuses. To top it off, my throat is also the only alternative air supply route, since I have been reduced to breathing somewhat ineffectively through my mouth.

In a happy development, regular infusions of warm dihydrogen monoxide have proved effective in halting the progress of the enemy down my throat. My near-infinite supplies of this weapon have caused widespread consternation among the enemy leadership. Reports from the front indicate that the southern generals have pulled their troops back, and are heading north to join their commander at the Siege of the Sinus Cavities, which promises to be the . The battle being waged there is fierce, with neither side giving quarter. I have given orders that enemy troops are to be mercilessly slaughtered in cold blood, unless they swear blood oaths of lifelong fealty to me. Otherwise, within the confines of my body, the Geneva convention is hereby repealed.

While my brave soldiers fight heroically to hold the Forts of the Ostia, even they need time to rest and regroup. Bombing runs by the Otrivin Airborne Nasal Drop Squad are carried out whenever the fighting gets too rough. As Lord High Supreme Commander by Divine Right, the responsibility falls upon me to balance the costs of this form of attack with the lives of my faithful soldiers.

This choice is hard - a lesser man may be unequal to it. And yet, I must make the decision. Millions of lives may be lost in this War of the Respiratory Passages, but their sacrifice will ensure that the organism lives on.

To all those who must die, your sacrifice will not be in vain. This war will be forgotten.

That's right. It will be forgotten. Not remembered. Not sung about for centuries. It will be banished from the Neuronal Archives as useless information, never to be recalled again. That's the whole point of recovering from a minor sickness. You forget about it. It's not worth remembering.

But these are thoughts for happier times. Right now, I must order another air strike against the rapidly advancing forces of the enemy. Victory will be mine! Onward!

Sunday, December 18, 2005

Diatribe

*Warning - ritual diatribe against MU's stinking system and its consequences follows.*

On Saturday, we suffered through our last exam - Software Engineering was the name of this final torture. Very useful subject, as far as the software industry goes. Unfortunately, it doesn't meld very well with MU's exam-oriented style(hell, nothing that really qualifies as engineering melds properly with it), so the whole thing just degenerated into another contest of memory. Predictable, but no less painful.

So far I've been under the impression that the fellas in charge knew that their system was fundamentally incompatible with the maverick field of computing. Maybe the inertia of this massive system was why they left it the way it is. Now I've begun to wonder if that was an overly charitable conclusion. Maybe they're just too dumb to realize it. Fine. Nuts to them - I'll be out of their organized insanity in another semester. There's no hope of fixing it, any more than there was of fixing the useless mess that they made of the secondary education system. These idiots are incapable of realizing that while memory and knowledge are connected, they are not identical.

Since I've been reading a lot of Joel Spolsky recently, I'll quote him on interviewing:
Just for fun, here is the worst interview question on Earth: "What's the difference between varchar and varchar2 in Oracle 8i?" This is a terrible question. There is no possible, imaginable correlation between people that know that particular piece of useless trivia and people that Fog Creek wants to hire. Who cares what the difference is? You can find out online in about 15 seconds!
The dudes who run our technical education are the kind who think asking questions like that one is a good thing. They can't distinguish between useless trivia and the kind of skill and understanding and knowledge that gets used in engineering or research. There is a place for that kind of trivia - if you work on anything moderately complex, you will eventually end up with a whole lot of little details like this in your head. I know dozens of obscure things(ask any of my bored-to-death pals) about dozens of obscure subjects, but I never sat and studied the damn things! They just stuck in my head as a consequence of a lot of reading.

To intentionally fill your mind with the kind of information that could be looked up in a minute is a slightly odd pastime, but perfectly acceptable. I've done it myself, on occasion. But to force it upon others is positively criminal. And to call it an education on top of that is equivalent to mental genocide. Sort of like those mad priests of the Spanish Inquisition who burnt 'witches' at the stake, and told them they were saving their souls besides.

In any event, there's nothing I can do about it. One strives to minimize contact with these people - argue too long with a fool and you'll become one yourself. Better to learn all the useful stuff on the side, like some of us have done. A lot of people will get away without any real skill, but in the long run, we geeks will have the last laugh. We always do. We did build this world, after all.

I remember this incident last year during CPLAB(Java) practicals. It was the first time I saw how a lot of my classmates wrote code. I knew they were bad, but I had never expected to see what I saw.

Our class was divided into three batches - A, B and C. For CPLAB, A and C had one teacher, and B had another one. Those of us who were in the B batch were considered lucky, since the prof had declared that we could use any language for the project. No prizes for guessing how many of them used VB...Not even 'good' VB - no COM, Web programming, or anything. Just the usual 'draw the interface, create a bunch of recordsets, fire a few queries, and display.' Me and Hrishikesh(Kolhatkar, not Thite) produced a fantastic Java project, but then we belong to the tiny minority that enjoys writing code, unlike most people.

The A and C batches had a more sensible teacher. CPLAB is basically a course in Java, so she declared that all projects had to be in Java. This made several people very unhappy, but it was the smart thing to do. Or so we thought.

It was right at the end of the semester, when the projects were due. The B batch had finished, but A and C were busy working away, struggling to finish. And then I saw how the other side coded. This is the general algorithm:
  1. Figure out what you need to accomplish.
  2. Search through the Java Complete Reference until you find a piece of code that does it.
  3. Type it in, usually with only two fingers. This is where most of the effort was expended.
  4. Struggle to debug it, wondering angrily why it doesn't work properly.
  5. Call for help from me, Hrishikesh or Sagar(who was busy working on his own project and trying to remove a persistent bug that eventually became a feature).
  6. Watch as the unfortunate debugger gapes in horror at the morass of contradictions that unfolds on the screen before them.
  7. Thank the aforementioned debugger who staggers away having rewritten half the code, wondering what possessed him to help out.
Hrishikesh and I ended up helping so many people that we could have started a consultancy and raked in the moolah that day. I kid you not.

To be fair, though, there were a few who were actually trying to understand what they were doing. These people were more fun to help, but it's a headache without the javadocs. People, download the docs, for heaven's sake! You don't have to remember a gazillion obscure function signatures to be a good developer. They're all written down nicely for you. Documentation is your friend. So is Google. Use them, tinker a lot(this is very important) and you'll be coding cool stuff in no time.

For those who still have more than a year of MU engineering left, hang in there. Do the following stuff:
  1. Read Paul Graham and Joel Spolsky.
  2. Write code of your own. Learn another language. Try something really high-level like Python or Ruby.
  3. If you don't understand C pointers, don't despair. Not every mind can handle the weird thought patterns involved.
  4. Learn something about algorithms - you don't have to become an expert, but the mind expansion is well worth it. Try out TopCoder. Learn stuff at USACO.
  5. For God's sake, read something more than your textbooks! You need sources for new metaphors if you want to improve your thinking.
  6. Learn how to write fairly well - the best programmers are also fantastic communicators. You might want to get yourself a blog. It's a great way for blowing off steam too!
And the principle that underlies it all - Have fun doing it! This is the most important thing. If you don't enjoy computing, it might be best to get out early. (Wow, I sound like some guru handing out sage advice!)

Finally, don't pay too much attention to what I write. I'm just ranting most of the time.

Tuesday, December 13, 2005

Polish Justice

Check out this insanely hilarious account of how the Polish police react to a mugging. Now this is what I call motivated service!

Sunday, December 11, 2005

The Church-Turing-Deutsch Principle

I don't know how many of my readers will find this interesting, but I give a thumbs up to Michael Nielsen » Blog Archive » Interesting problems: The Church-Turing-Deutsch Principle. It's about an interesting extension of the Church-Turing thesis by David Deutsch. I like reading this sort of stuff, so if anyone else likes it, leave a comment so I know who else shares my weird tastes...

Now that's what I call an illusion!

Check out this really cool illusion. Beats the pants off any other illusion I've seen!

Friday, December 09, 2005

At the halfway mark

First off, my pal Sagar is losing it.

Oddly enough, this has caused my opinion of him to actually improve. Now if only he'd resume competing at TC...

My sister has begun studying probability. Those who know me realise that I'm mentally preparing myself for the terrible ordeal that will undoubtedly follow. Those who don't should know that my sister has no memory for any mathematical skill I(or anyone else) teach her. Give her six months and she'll forget anything mathematical. Unfortunately, as the mathematically competent older sibling, it devolves upon me to teach her. Some idea of the horror with which I view this task may be formed if one considers that I consider teaching her only a step above robbing graves and eating the contents. Raw.

She can't be that bad, you say? Read on...

A couple of hours back she came and asked me a series of weird questions, ultimately proving that she'd forgotten some really basic algebra, namely, how to solve an equation of the form ax = b. Furthermore, she seemed completely comfortable dealing with a probability value of 6/5, and refused to believe that fractions could be greater than 1 for a few minutes...

For the mathematical pedants among you, in the example, a, x and b are all real numbers.

We had Image Processing yesterday. Fantastic exam - I loved it. People seemed pretty happy about it too. Sagar says he messed it up, but as I said before, he's losing it.

Saw an episode of Coupling earlier this week. Nearly died of laughter. Definitely must watch more of it...

TC had an SRM yesterday, but I was feeling a bit tired for some reason, so I decided not to. My net connection also failed for a few mins before it started, but that had nothing to do with it, though it did impose an air of finality over the decision...

Anyway, it turned out to be the right decision, since the problem set was highly nonstandard, to say the least. I have nothing against hard problem sets, but memoization on a division 2 500 is a little too much! The problem statements weren't exactly models of perfect clarity either. Still, I kinda liked the div 1 250(also div 2 500) and the div 2 1000. They were fun problems, at least in the practice room.

Meanwhile, I seem to be getting some flak from various parties regarding something I said about vacuous bimbos in this post. Apparently I need to clarify something. Here goes:

A quick check at Dictionary.com shows that in fact, the term vacuous bimbo is oxymoronic. Bimbos are vacuous by definition. They also seem to be somewhat overly interested in their own sex appeal, which connects nicely with what I was talking about in the offending paragraph.

Thus, the problem reduces to this: most Engg gals are vacuous, but not vacuous bimbos. Furthermore:
  1. While vacuity is always difficult to tolerate, vacuity coming from a so-called 'bimbo' is somewhat easier to handle, since enduring their empty-headed nonsense isn't as unpleasant. Very painful statement, but one that is sadly true. Has to do with evolutionary mechanisms of ensuring that a person's genes make it to the next generation. Blame the dude who did the whole 'creating the Universe' thing.
  2. See the title at the top of the page? That's right, it actually means something. Focus on the word 'subtlety'. In a supremely ironic gesture, I give you a link to the definition of the word 'subtle'. If you can't see the irony in that, move on to the next point. If you can see the irony in that, pat yourself on the back and move on to the next point.
  3. The point concealed in the little paragraph that started all the trouble was one that's so old and cliched that it increments our little irony counter all by itself. It's the famous one that goes "The system sucks!". In this case, my beef with it is that it allows vacuity to persist beyond an individual's 15th year, and that it does not make proper use of the redeeming qualities that the vacuous do possess.
Frankly, I can't see how one could be pissed off about these commonplace observations about some pretty obvious trends. It's not like they're absolutes that always hold. Absolute generalizations are not something one bandies about casually. Indeed, those who mistake my comments for absolute generalizations are clearly guilty of the sin of vacuity and/or stupidity.

However, I am a generous and forgiving chap who loves taking the wind out of the sails of his adversaries. After all, why blame on malevolence that which could just be incompetence or ignorance?

Therefore, I magnanimously forgive my detractors(*gestures in an expansive flourish whose benevolence seems to encompass all of creation*) and ride triumphantly into the sunset.

*DRUM ROLLS ALONG WITH ASSORTED FANFARE*

Tally ho, chaps!

Monday, December 05, 2005

Can you enhance it?

One of the staples of a Hollywood movie involving law enforcement or something along those lines is a scene involving a bunch of people crowded around a computer monitor, looking at some kind of image - for example, a picture of a car racing away into the distance.

Some guy tells the chap with the keyboard - "Can you enhance/zoom in on this?" - pointing at the license plate.

Now at this point, some weird stuff happens. What we would expect is that the guy will draw a little rectangle around the area and blow it up. Instead, you hear some furious typing sounds, and a large rectangle appears, and shrinks down until it fits perfectly over the thing the first dude pointed out. Then it expands, usually accompanied by more furious typing.

My question is - What the hell is the guy typing? How on earth did he tell this miracle application where the area of interest was? In 99% of the flicks I've seen, there's no sign of a grid or any other form of coordinate system. He isn't even moving it with the keyboard - it just sort of appears at some random point on the screen and then helpfully shrinks down to just the right spot. Weird...

Even more interesting is that no one ever seems to say "Sure I can zoom in, but it's no good, because the camera never captured that detail in the first place. You'd just see a weird blurry hodgepodge of colours." Seriously, I doubt that even a really good interpolation algorithm is going to be able to make sense of the little squiggles that constitute the contents of a license plate.

And of course, there's that thing where they zoom into some tiny reflective surface and see what was going on reflected there...

What kind of magic algorithm do these chaps use to enhance everything?

Oh, and the reason this blog post turned up is because Image Processing is the next exam on Thursday. Off I go now to grok the frequency domain and image enhancement using the Fourier transform.

Sunday, December 04, 2005

Intelligent Design

The sheer idiocy of the 'Intelligent Design' brigade is the ultimate proof of the existence of God. After all, to continue trumpeting such nonsense in the face of overwhelming evidence requires a level of stupidity and self-deception that could only have arisen through divine intervention.

Thursday, December 01, 2005

Write Things: Two papers down and so am I!

Write Things: Two papers down and so am I!

Looks like I'm on a roll - this is yet another trackback. As always, go read the post first. Like most things Mihir, it's good for a laugh. This is a sort of point-by-point reply, so you might wanna keep it open in another window - or tab if you're a more enlightened individual.

2 papers in three days? Ha - our smallest gap between papers is 3 days! *Laughs uproariously*. Of course, that just means that you forget everything on the last day and have to study like crazy all over again.

Muggus: My class has the ultimate muggu - the living tape recorder without a fast-forward button. Knows the contents of every set of notes and most textbooks word for word. Has very little idea what they mean, but seems to survive on word-association alone. I know because he once explained something(branch prediction in the Pentium?) to a group of people, who didn't get a word. When asked to explain better, he proceeded to say the whole thing again, just more slowly...

Eventually I butted in and gave the unfortunate chaps a translation of what he said in simple English. Really simple English. He was quoting from an American author, so naturally the nitwits couldn't understand it. Sheesh. After at least 12 bloody years of education in English, they still can't understand the language. It's enough to make an atheist take up religion, because this sort of stupidity absolutely requires divine intervention...

And then the joke of the century - our muggu comes to me and says "What book did you get that from? Let me know because I haven't understood it either."

I would have told him the truth, but I was too busy ROTFL. Lost it a little more when I realised that there are actually people who consider conversation with me equivalent to reading a sensible textbook. The only guy who uses my kind of language is the one who doesn't know what it means. Go figure...

Scholarly type saying "Ok paper": Ladies(?) and gentlemen, please refer to my previous blog post on how writing a genetic algorithms framework netted me 10 marks without any particular studying on my part.

Well what do you know - I seem to be the real McCoy. And I'm modest, too. :)

*Red Alert - Sensors detect off topic disjointed Trekkie nonsense ahead*

The *real* Dr. McCoy, Star Trek : "Dammit Jim, I'm a doctor, not an engineer!"

More likely : "He's dead, Jim."

Now the Star Trek engineer was Scotty - the miracle worker. The typical conversation between him and Captain Kirk went something like this:

Kirk: "Mr. Scott, how long until you can get our engines operational, supercharge our phaser batteries, recalibrate the transporters, and invent a fancy weapon to defeat the Klingons?"

Scotty: "At least two weeks, sir."

Kirk: "You've got twenty minutes."

Scotty: "Aye sir."

Needless to say, he then proceeds to do all of the above, also cramming in a crawl in the maintenance tubes and some fancy jiggling with the controls of the transporter. Grumbles about it all the way through, and gets drunk on Scotch(a little cliched, eh?) at the end.

Every MU engineer understands this life, because we perform similar miracles at the end of every semester while submitting our term work files, during vivas, and finally during exams.

It seems entirely possible that Scotty is a graduate of MU's engineering program three centuries hence. All the signs seem to point that way. Mind you, I'm still a little wary of anyone who refers to a warp core as 'ma wee bairns'...

*Stand down Red Alert*

Girl saying 'Bad paper' whilst giggling and trying to look cute: We'd appreciate a few more of these around. Engineering is bad enough with all the babes off in less demanding streams. After four years of this crap, you begin to wonder if vacuous airheaded bimbos are more interesting than engineering females, who are often equally vacuous and rarely have the redeeming qualities of the former category. Plus they think they have some engineering skills...

Yeah, gender stereotyping. Mea culpa. Four years of MU engineering does that to you. Besides, it's not like most guys are any better. It's just that you tend to find techies among them more easily. For some reason, most girls in engineering lack true passion for the subject. Possible reason: they're only in engineering because it's the traditional punishment for scoring high marks in the 12th, and they didn't go into medicine.

Interesting definition of a muggu at the end of the post. Reminds me of one of my favourite insults - "Even if we doubled his IQ, he'd still be dumber than a flea with a learning disability."