Santa Clause: Naughty or Nice?

December 22nd, 2007

Santa Claus. Naughty or Nice? Is Santa a symbol of giving who brings joy to millions or an evil corporate shill who promotes shameless materialism?

Award extra points for arguments that are venomous and vitriolic. We don't want no apologists in this debate!

 

Crunchy or smooth?

December 21st, 2007

Peanut butter. Its loaded with calories, but absolutely delicious and goes well with with jelly. But which is better: crunchy or smooth?

Extra points will be awarded for arguments that involve religion or politics! Voters - if an argument skillfully brings up the topic of the Iraq war, give it an extra point!

 

Fun with Fibonacci

December 12th, 2007

Just read an interesting blog post about comparing Python and Haskell code to calculate the Fibonacci sequence. I wrote a faster version, just for the hell of it. I realise that it is not a fair comparison any more, and doesn't prove anything, but it does demonstrate a useful optimization technique. Here's the code...

from time import time

def memoize(f):
    f._cache = {}
    def do_f(n):
        if n in f._cache:
            return f._cache[n]
        r = f(n)
        f._cache[n] = r
        return r
    return do_f

@memoize
def fib(n):
   if n == 0 or n == 1:
      return n
   else:
      return fib(n-1) + fib(n-2)

if __name__ == "__main__":
    start_time = time()
    for i in range(36):
        print "n=%d => %d" % (i, fib(i))

    print "Time elapsed: %f" % (time() - start_time)

When I run it on my machine, it claims to take 0.00000 seconds. Damn, thats fast!

 

Bountiful

December 7th, 2007

My employer has placed a number of bounties for wxPython features. Pays cash!

wxPython Bounties
 
Search for Posts
2013
 
2012
 
2011
 
2010
 
2009
 
2008
 
2007
 
2006
 
 
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan