Skip to content

Instantly share code, notes, and snippets.

@kylemacey
Created March 20, 2017 18:19
Show Gist options
  • Save kylemacey/54c808495d62aeb5a3a2d26ab710cfbb to your computer and use it in GitHub Desktop.
Save kylemacey/54c808495d62aeb5a3a2d26ab710cfbb to your computer and use it in GitHub Desktop.
A calculator for holes in memory
class RachelsPoem
attr_accessor :holes_per_year, :years, :split_after_years
attr_reader :total_holes
def initialize(holes_per_day:3, years:23, days_per_year:365.25, split_after_years:7)
@total_holes = 0
self.holes_per_year = holes_per_day * days_per_year
self.years = years
self.split_after_years = split_after_years
end
def calculate!
while years > split_after_years
self.years -= split_after_years
# Add `split_after_years` number of holes
@total_holes += (split_after_years * holes_per_year)
# split holes
@total_holes *= 2
end
# Add remaining years' holes
@total_holes += (years * holes_per_year)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment