Tuesday, July 29, 2008

A bit of improvement

I'm in the institute lab right now, booting from a pen drive (Slax). But tomorrow I'll get my external HDD and plug it in and try to be productive. These labs are only meant for 'academics' which means there are caps on downloads, so I can't even download firefox without it being interrupted. Also we haven't got our IDs yet, so this connection is thanks to a senior who was kind enough to let me use his account.

Also there is a firewall/proxy which means no IM sites or IM protocols are allowed. This does kind of suck, but it is better than nothing. And this is only till December ( or so I hope ). Cheers, I'll update this tomorrow.

PS. No CD drives on any computer, how do I install Arch? Probably go home and do it

Monday, July 28, 2008

Still no computer

So the second time I'm in a cyber cafe. In certain respects private universities aren't much better than public ones. We still haven't got ID cards, which means no net/linux access. Which means no coding too.

Other than that its been pretty good, playing football and table tennis. But a bit tiring too. Its been raining a lot today, which means there isn't much to do. We had the first couple of lectures today, but nothing new was taught.

This is boring, but the situation is likely to improve in a few days.

Friday, July 25, 2008


Well, I'm here, or I've been here for 5 days now. Since we haven't got ID cards yet, there is no computer access, so I'm writing this from a cyber cafe. The last few days have been a bit boring. With no studies, playing and reading seem to be the only things you can do in 24 HOURS!.

I haven't written any code in days, but I have managed to read Hutton's Haskell book, which is really good. This place's library is awesome for all the computer science/programming related books they have, now I just hope I'll have linux access in the labs. For atleast four more months personal computers are not allowed in the rooms. So it might be next year (read Jan 2009) before I actually have my own computer again. Till then I'll just hang on to the external harddisk.

Thursday, July 17, 2008

Graffiti: disaster

I Gitted Graffiti yesterday, and made an error in adding the files to version control, so I decided to undo the changes and because Git complained, I added -f.

git rm graffiti -rf

BOOM! Graffiti is gone.

Except for the basic style parser which I was writing at that time, which was saved by Kate.

I'm not blaming Git, just my stupidity.

I usually don't version control as soon as I begin a project, since I like to get the structure right, without having really bad log comments. From next time, versioning first.

In retrospect this is a really bad week. Experience isn't the most fun teacher.

Programming: The invisible wall

In the past few weeks, as I've tried and failed at various projects, there has been a realisation that you can only go so far with random reading and coding.

The first few years of programming are spent coding projects pretty minor on the algorithms/data structures side.

But when you finally start growing out of it and when 'cool' projects for you start to become more complex, a seemingly invisible wall smacks you. The wall seperates amatuer and scientist. And unless you are/I am prepared to study, that wall isn't gonna give way.

Crossing the wall is going to require some serious studying, where I actually try to solve the exercises at the back of Algorithms rather than just read the book. At college I'll probably be able to get my hands on a hard copy.

And once this wall is broken, there will be more walls to break.

A failure in the codejam or how I blew up my brain

Thursday morning, I saw the problems and took a printout of the Flyswatter. Then I spent about 3 hours figuring out the right area calculations, without success.

Then I tried hacking away at the other 2 problems for a total of 1.75 hours. Again failed.

Result: A total brain burnout

Feeling: Really down for my not so leet algorithmic skills.

Lesson learned: I seriously need 4 years of formal computer science education.

Monday, July 14, 2008

Graffiti and more

It turns out parsing CSS according to specifications is no mean feat. So I am going to stall that for a moment, or implement a bare bones parser specifically written for Graffiti, and just plow along with Graffiti and doing what I can do, properly.

Maybe later ( read quite a few months ) I'll write a nice SAC compliant CSS parser and hook it into Graffiti.

Whatever I want to do, things aren't going to be moving fast. On Sunday I'm leaving for university ( DA-IICT ) and that involves a lot of pre-leaving things to do. And the week after that will go in getting settled there and taking a look at the computing facilities. I'll probably be taking a external HDD with all my files and I might just do a blind copy of this hard disk itself so I can boot Arch their if it is allowed.

Thursday, July 10, 2008

Always Turn Left

This is with reference to the Google Code Jam practice problem.


This problem initially seemed vexing. After a little bit of thought about using bit twiddling to represent directions, generating the right codes was easy.

If you have any experience with hexadecimal numbers, it should strike you that the direction table with 4 directions each of which can be yes or no, is a big hint that bit twiddles are exactly what is needed. Which means powers of two

N, S, W, E = 1, 2, 4, 8

Now I'm not going to show how you combine them, but here is how you get the code directly in Python ( somewhat similar in C ):

def code(dirs):
return '%x'%dirs

After this I scribbled a lot on paper, mapping the small input to the maze. It was easy to figure out that the problem could easily be solved by going both ways because always turn left means that you will visit every part of the maze if you go both ways. I wasted a lot of time thinking how to orient the grid, until I read the specification that the entrace is always at the north.

But there was another problem, how to generate a perfect size grid for a dynamic problem like that. I didn't want a 10000*10000 grid all the time, that would be very inelegant. First I tried using links for each Cell, but the problem is resolving W-E or N-S relationships would involve backtracking to find the adjacent Cell. This flummoxed me for a LONG time. Then I read João's idea [perfect maze size] and it hit me like a rock. This problem really requires you to break some preconceived notions, like a multidimensional array being the best representation for a Grid. A dictionary with coordinates as keys turned out to be perfect for this problem. After this the solution was dead simple, walk forward, preserving the right coordinates, then turn around and walk back, overlaying existing directions with new ones you find.

Write a simple comparator function for coordinates, and use it to sort the grid and print it, and you have the solution in Python

In general the practice problems are creative, all they require a bit of common sense, some unconventional thinking and perhaps a few years of experience. Mainly it's about how elegant your code can be. I'm just hoping the real ones will be easy too. But irrespective of that, I'm not qualified to receive even a T-shirt, since I'm under age.

Saturday, July 05, 2008

Book Review: The Curious Incident of the Dog in the Night-time

The Curious Incident of the Dog in the Night-time by Mark Haddon is a crime novel. Except it's written from the point of view of a 15 year old autistic boy.

This book was actually released in 2003 so I'm a bit late for the review, but I just stumbled upon it a few days ago at a friend's place. And the bright colour and really long rambling title really intrigued me.

So, meet Cristopher Boone, who wants to be an astronaut, loves animals more than humans, has a photographic memory and brilliant logic but can't tell what other people feel and has no notion of metaphors and cultural references. Unlike many of us he cannot follow the 'I am thinking about what you are thinking about what I'm thinking' process that often happens. The only concept of emotion he has is a list of emoticons expressing common faces.

Haddon does not try to invoke pity, Christopher is in no way purposely projected as someone worse than us. He lives with his Father and thinks his Mother is dead. When his neighbour's dog is killed he sets off to find the killer in an independent manner, in the process escapes to London and comes to reality with the fate of his Mother.

Since the story is told from his view, and his lack of emotion and future projection means that he has no reason to lie leads to a very truthful story, even to the point of making normal readers squeamish. He writes about poo, and sex and swear words with no change in tone than if he was talking about the weather. He doesn't feel death when he narrowly misses it and when he gets an A grade in his Math A-levels the only thing he feels is

At 134 pages the book is a quick read and there is no actual crime-solving but Christopher's need to fit into the world is very well written and a window into the mind of autistic people. At the same time it lets us marvel at the beauty of our brain to reject so much information and yet generate so much of its own with no bindings to any law.

Along the way the book has a sprinkling of math, including naming all chapters with prime numbers. Christopher almost always goes on cubing natural numbers or mentally calculating powers of 2 just to overcome nausea.

I doubled 2's in my head because it made me feel calmer. I got to 33554432, which is 225, which was not very much because I've got to 243 before, but my brain wasn't working very well.
-- Christopher Boone

But at the core the book is humourous with Christopher's long rambling sentences and attention to details leaving you chuckling. Mark Haddon has done an excellent job.

Friday, July 04, 2008

He stole the words out of my mouth :)

CamenDesign: A List Of People Who Need To Stop Writing Software

I'd also add Creative Nero, Adobe PDF Reader and Falcon.

Half of "Windows Pain" comes from the crummy applications sitting on top of it.

Wednesday, July 02, 2008

Graffiti first view

Word wrapping is now implement and I've got a fairly decent design for the first version

So here is the client code it took

import sys
import pygame
from pygame.locals import *

import graffiti as g # Line 1

g.init() # Line 2

s = g.spraybuilder.parse_string(

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean id diam. Curabitur lectus. Nullam ultricies ultrices tellus. Praesent id turpis vitae lorem varius posuere. Donec id diam. Nam risus sem, aliquet ac, dignissim eget, aliquam ac, dolor. Aenean lacus metus, eleifend eu, elementum ut, lacinia non, nisi. Morbi odio. Aenean id massa. Ut arcu urna, elementum et, iaculis ac, lacinia eget, dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas eleifend facilisis dolor. Quisque eget nulla. Sed ut eros. Maecenas ut diam. Nullam tellus urna, sodales ac, cursus nec, tempus ac, purus.

Aenean malesuada est quis velit. Nulla vitae nunc. Integer gravida. Curabitur purus velit, egestas quis, aliquet quis, mattis ac, orci. Aliquam ac lectus. Mauris congue orci faucibus est. In orci odio, sodales at, pretium nec, dignissim et, neque. Suspendisse potenti. Fusce eget ante. Etiam purus ligula, placerat tempor, pellentesque quis, tincidunt accumsan, turpis.

) # Line 3

surf = g.spray.SprayRenderer(s.sprays[0]).render() # Line 4

pygame.display.set_mode((800, 600))
pygame.display.set_caption('Spray Rendering')
screen = pygame.display.get_surface()


while True:
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):

screen.blit(surf, (50, 50, 800, 600)) # Line 5

to generate this

I'm doing a bit of internal access in Line 4 right now, but that will be fixed.
If the design remains good, it should remain that easy ( just 5 lines! ) to use for all time