Saturday, March 24, 2012

Some nutheads fight over the day and year on which he was born. Some good-for-nothing give-me-some-work-I-am-jobless stupids get drunk and raise a ruckus over some insignificant statement made by some foreigner. Some politician-turned-businessmen use his name to misguide youth and use them to attain power.

We are in an age where slogans of "जय भवानी जय शिवाजी" are met with skepticism and anybody shouting them is branded as a fundamentalist or a marathi/maratha chauvinist. It hurts to see such a great and secular personality being colored religiously and regionalistically. It hurts to see a particular caste claiming "ownership" of his legacy. It hurts to see elaborate divisive strategies being cooked up under his name and the youth falling for those.

Let's not move away from what he stood for, what he fought for and what he cared for. I dedicate this poem to the eternal source of inspiration and enthusiasm, the one and only, न भूतो न भविष्यती, छत्रपती शिवाजी महाराज!

Friday, March 9, 2012

What you need to know :
  1. Memoization
  2. Python decorators
Here is fib.py
def fibo (n) :
    print "fibo called with arg :", n
    if n in (0, 1): return 1
    else : return fibo (n-1) + fibo (n-2)

print fibo (5)
# prints
# fibo called with arg : 5
# fibo called with arg : 4
# fibo called with arg : 3
# fibo called with arg : 2
# fibo called with arg : 1
# fibo called with arg : 0
# fibo called with arg : 1
# fibo called with arg : 2
# fibo called with arg : 1
# fibo called with arg : 0
# fibo called with arg : 3
# fibo called with arg : 2
# fibo called with arg : 1
# fibo called with arg : 0
# fibo called with arg : 1
# 8

print fibo (3)
# prints
# fibo called with arg : 3
# fibo called with arg : 2
# fibo called with arg : 1
# fibo called with arg : 0
# fibo called with arg : 1
# 3

# Too bad!!
# So much redundant computation.
# Let's make it better!

from memoization import *

@memoize
def fib (n) :
    print "fib called with arg :", n
    if n in (0, 1): return 1
    else : return fib (n-1) + fib (n-2)


print fib (5)
# prints
# fib called with arg : 5
# fib called with arg : 4
# fib called with arg : 3
# fib called with arg : 2
# fib called with arg : 1
# fib called with arg : 0
#8

print fib (3)
# prints
# 3
Here is memoization.py