Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@spraints
Created May 7, 2015 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spraints/d520331db7a4ea8693da to your computer and use it in GitHub Desktop.
Save spraints/d520331db7a4ea8693da to your computer and use it in GitHub Desktop.
# To demonstrate what a "Bank of Dad" would be like
require "date"
INTEREST_PER_MONTH = 0.1
birthday = Date.today # replace this with the child's birthday
twentyone = 21.times.inject(birthday) { |d, _| d.next_year }
balance = 0.0
now = Date.today
while now < twentyone
show = false
if now.day == 1
balance = balance * (1.0 + INTEREST_PER_MONTH)
show = true
end
if now.sunday?
balance += 1.00
show = true
end
if show
puts "#{now} $#{'%.2f' % balance}"
end
now = now.next_day
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment