Skip to content

Instantly share code, notes, and snippets.

@trliner
Last active December 17, 2015 03:38
Show Gist options
  • Save trliner/5544191 to your computer and use it in GitHub Desktop.
Save trliner/5544191 to your computer and use it in GitHub Desktop.
Calculate the circumference of a certain number of acres.
SQUARE_FEET_PER_ACRE = 43560
def circumference_in_feet_for_number_of_acres(number_of_acres)
area = number_of_acres * SQUARE_FEET_PER_ACRE
radius = radius_of_area(area)
circumference_of_radius(radius)
end
# Math::PI * (r ** 2) == area
# r ** 2 == area / Math::PI
# r == Math.sqrt(area / Math::PI)
def radius_of_area(area)
Math.sqrt(area / Math::PI)
end
def circumference_of_radius(r)
2 * Math::PI * r
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment