Last active
August 29, 2015 13:56
-
-
Save mnstrspeed/9251802 to your computer and use it in GitHub Desktop.
Fucked.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, timedelta | |
import itertools | |
monthly = lambda first: (first + timedelta(days = i * 365 / 12) for i in itertools.count()) | |
weekly = lambda first: (first + timedelta(days = i * 7) for i in itertools.count()) | |
repeating = lambda first, dates: (lambda since: next(d for d in dates(first) if d > since)) | |
transactions = [ | |
("Rent", -300.00, repeating(date(2014, 3, 1), monthly)), | |
("Paycheck", 100.00, repeating(date(2014, 3, 24), monthly)), | |
("Scholarship", 100.00, repeating(date(2014, 3, 24), monthly)), | |
("Groceries", -50.00, repeating(date(2014, 3, 3), weekly)) | |
] | |
balance = 1337.42 | |
prev = date.today() | |
while balance >= 0: | |
transactions.sort(key=lambda t: t[2](prev)) | |
date = transactions[0][2](prev) | |
for description, amount, f in transactions: | |
if f(prev) == date: | |
balance = balance + amount | |
print("{}\t{:20}\t{:>+9.2f} EUR\t{:>+9.2f} EUR".format( \ | |
date, description, amount, balance)) | |
prev = date | |
print("\nBalance: {:+.2f} EUR".format(balance)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment