Live data from Hacker News

The Evolution of a Python Programmer

gist.github.com

41–45 of 45 posts

Re: The Evolution of a Python Programmer

#43

Half of those are incorrect implementations that junk the stack and most of the rest are idiotic rebaked jokes from the late 90s. Nowhere near to http://www.willamette.edu/~fruehr/haskell/evolution.html which is not only enlightening but actually funny when it tries to; or even to http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.... which was funny when it started and still is the original. Can we stop mak…

I actually thought this was the best thing I read today. So please don't stop posting these.

If you want to see multiple interesting solutions to the same problem, and use Vim as your text editor, then check out http://vimgolf.com

Re: The Evolution of a Python Programmer

#44
post #39
post #23

Earlier quoted context omitted.

A 'lazier programmer' who actually checked the optimization of various factorial methods? There's a joke in there somewhere...

a lazy programmer is one who will write a shell script in an hour to generate three lines of boilerplate...

It's worth it, if you have to type the boilerplate code hundreds of times. Consider the time wasted in debugging errors due to typos etc. It's even more worth if that shell script (or, in my case an emacs yasnippet) is parameterized.

Re: The Evolution of a Python Programmer

#45
Memoized version:

  class Factorial(object):
    def __init__(self):
        self.n = 0
        self.fact_n = 1

    def next_fact(self):
        self.fact_n *= (self.n + 1)
        self.n += 1

    def prev_fact(self):
        self.fact_n /= self.n
        self.n -= 1

    def fact(self, n):
        if n == self.n:
            return self.fact_n
        elif n > self.n:
            # start from self.n working forward
            self.next_fact()
            return self.fact(n)
        else:
            # start from fact_n working backwards
            self.prev_fact()
            return self.fact(n)


  fobj = Factorial()
  print fobj.fact(6)
  print fobj.fact(8)
  print fobj.fact(3)
Post reply on HN