March 9th 2008 Popeyes Redux

As a followup to “Popeyes”, here’s the same code implemented with Python:

#!/usr/bin/env python

def popeyes(n):
    if n < 1:
        return 0
    elif n < 3:
        return 1
    else:
        return 2 ** (n / 3 - 1)

if __name__ == "__main__":
    import sys

    n = 0
    try:
        n = int(sys.argv[1])
    except IndexError:
        n = input("How many chicken fingers? ")
    print "You will receive %g dipping sauces." % popeyes(n)

Nothing special, but it’s a cool comparison to Haskell’s code.