Fun with Generators

Wednesday, January 14, 2009


Pointless post, just an example of a python generator (and list comprehension)

#! /bin/env python
from operator import add

originalPrincipal = 5300
ccAPR = 0.099

def ccBalance(principal, apr):
while(principal > 1.0):
minimum_payment = principal * 0.02
interest = ((principal * apr) / 12)
principal -= (minimum_payment - interest)
yield (principal, minimum_payment, interest)

leCardDeRipoff = ccBalance(originalPrincipal, ccAPR)
payments = [(x,y,z) for x,y,z in leCardDeRipoff]

print "paying the minimum balance on a credit card with"
print "a current balance of $"+ str(originalPrincipal) +" and"
print "an APR of " + str(100 * ccAPR) + "% will",
print "take " + str(len(payments) / 12.0) + " years"
print "and result in paying $",
print str(reduce(add, [z for x,y,z in payments])) + " in interest"



This is by no means a fast solution, take it with a grain of salt.... and wordpress flattens everything in code tags

Labels: ,

Its that time of year again.

Saturday, January 03, 2009

Its that time of year again where I have to decide whether or not I should renew my subscription for ericrose.net, a decision made slightly easier by the generous hosting fee that I get by hosting through QuickPacket.com (CamelCase, one word). Ericrose.net was initially created as a travelogue for my adventures in Germany, and it served that purpose quite well. I have since returned to the US and ericrose.net has, by virtue of that fact, lost a bit of it's raison d’être. That is not to say that once I set foot back on American soil I returned to my life as it was, because I certainly haven't, but rather that my time in Germany was dedicated to experiencing The New which was something that I didn't feel like I was doing at Clemson. My life since Germany has been spent in Boston, a city that upon setting foot in for the first time I had to find a place to live, and New York, to where I moved before I had any promise of employment, so even after returning from Europe I have still maintained my affinity for seeking things fresh and exciting. Even though I continue living my life with the same wide eyed curiosity and adventuring geist that served me so well in the past I have, for some reason, declined to engage in the introspection required to synthesize my experiences, thoughts, feelings, and accomplishments into blog posts. That is not to say that such introspection does not occur, it means simply that the result of my introspection is not a blog post. There are many reasons for this: I like to annotate my posts with relevant links and this tends to take a lot of time, I am reluctant to blog about things that do not have pictures associated with them and I often forget to bring my camera with me, I am employed/was pursuing a graduate degree in computer science which necessarily reduced the discretionary free time that I could dedicate to maintaining a website versus my other hobbies (running, cycling, reading, etc.), I maintain other web presences that represent information that I would otherwise sculpt into a blog posting (flickr, facebook, google reader, and too a lesser extent: myspace, yelp, and about a dozen more).

In 2009 I hope to both do and think things worth writing about and write about them because as websites like twitter gain popularity, I, like David Brooks, retain an appreciation for long form thought.

Labels: