Friday, December 31, 2010

Time limit exceeded- Error!

When running the same code for sorting integers, but on a test case of size of order 10^6 I realized that it took more than 5s to sort the integers in python.

Here is my code:

import time, profile
def timing():
    t1 = time.time()
    print "f1: %.3f" %(time.time()-t1)
    t2 = time.time()
    print "f2: %.3f" %(time.time()-t2)

def f1():
    lint = int
    list = [lint(raw_input()) for i in range(lint(raw_input()))]
    for l in list:
        print l

def f2():
    list = [int(raw_input()) for i in range(int(raw_input()))]
    for l in list:
        print l
    return'timing()', 'sort.tmp')

Vim is really programmers best friend like earthworms are farmers'
Vim helped me write a test case of this size in < 60 sec, and now I am there ready with a profiler and the time module to measure the time it takes to run that sort call.. The sort call that is a built-in function is probably not the culprit, I think in case I could parallelly carry on the reading and the sorting process the much needed optimisation can be brought..
This particular problem at the under the easy problems tab is not that easy to do in python.. Everytime I get TLE error..
Some handy commands in vim:
:set binary
:set noeol
let me turn off the automatic end-of-line vim adds to every file editted in it.. And the profiler and time tools are easily available on the web can be found using google!

Here is the profiler output.

>>> import pstats
>>> p = pstats.Stats('sort.tmp')
>>> p.sort_stats('cumulative').print_stats(15)
Thu Dec 30 16:17:31 2010    sort.tmp

         2103371 function calls in 114.964 CPU seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000  114.964  114.964 profile:0(timing())
        1    0.109    0.109  114.964  114.964
        1    0.000    0.000  114.964  114.964 :1(?)
        1   93.992   93.992  114.855  114.855
  2103357   19.643    0.000   19.643    0.000 :0(raw_input)
        2    1.110    0.555    1.110    0.555 :0(sort)
        2    0.110    0.055    0.110    0.055 :0(range)
        1    0.000    0.000    0.000    0.000 :0(setprofile)
        4    0.000    0.000    0.000    0.000 :0(time)
        0    0.000             0.000          profile:0(profiler)
        1    0.000    0.000    0.000    0.000

Suggestions solicited.. Just in case someone has faced this before, I have to submit a solution in python that sorts the huge integers in < 5 sec..

Monday, December 27, 2010

Thinking out loud

I am getting bored and laziness is getting over me. I think I have to do something to prevent myself from corrosion. That too very soon..
First thing first
i need to get something that challenges me to work on it..
I do have many things on my head, that may be one of the reasons I am doing nothing.
Okay, I should split it into small, reachable goals with deadlines..
I should first move my blog on django+google app engine
when done i'll think of other things, first this, thats it..

What's wrong?

The day since I have joined the company, i mean i have started a so called corporate life.. i am getting as bored as I have never been.
I miss the bunking classes (though i bunked very less of them), building castles in air (khayali pulao), driving my scooty, screaming at home about all the wrongs that are happening and how I could change it given a chance :P
Now when I have the chance, I don't know what am I doing?
The problem is not with the office, the project I am in is one of the most coveted one in my company, and even I found the technology very interesting. also there is no problem of time I think I now have more time than what I had in college... We have flexible timings and access to almost all of what one generally needs.. (Gmail, fb, google; these are normally blocked in other companies) So there is almost no problem on the professional and technical part of the life..
So what is going wrong? I think it is the social life, the personal part that is getting screwed up.. I feel lonely, unenthusiastic, wasted, in short terrible!
Any suggestions what I could do to improve my life as well as living..

Note: don't suggest make a boyfriend!

Wednesday, December 8, 2010

Flashing N900 Indian Version, for Skype support

If you are using an N900 you've bought anywhere in India then odds are that you are quite disgusted of your purchase. By the set bought in India I mean a set bought after N900 was officially launched in India and you purchased a set with bill! not a grey phone.. Like I did :(
I was not aware of this complete thing, later when I knew I could not stand this and hence I gave back the phone to the shopkeeper nd asked for a fresh one, with bill. And though the phone was brand new the experience was very bad. And I was smitten when I found that there was no skype, (for those not aware, skype integration is the expertise of maemo). Also there was a lot of stuttering when I played songs in the media player. To make things worse, there wasn't any call summary displayed when I made a call or used internet. Those who use an airtel sim and live in Rajasthan or places where *121# etc. only work and there is no support for listening to your balance can probably understand my situation very well!
So, finally 3 days back I decided to flash my device with the global firmware of fremantle latest release. Believe me it is the best thing to do with your phone. If you are really considerate for your phone, then do it! To do it literally simple. You are just three simple steps away from this pleasant experience called N900!
  1. Get the flasher from here.
  2. Get the firmware binary here.
  3. Read this manual.
And trust me you are good to go. Nothing happens, everything your calls, your wifi, your gui and SKYPE works better than before. And you get those call summary as well!!!
                        So go ahead and flash your device!!!
                        Happy N900...