According to the Tiny Tower Wiki the equation for calculating how much it costs to build a given floor is:
cost = 150 × floor_number 2
A simple way to evaluate this equation in Ruby would be:
floor_number = 10
cost = 150*(floor_number**2)
For those that build in chunks, rather than one floor at a time, it's nice to know how much you need to save before you can build a certain number of floors. Using Ruby once again, this is a trivial operation:
def calculate_building_cost_for(floor_numbers)
floor_numbers.inject(0) { |total_cost, floor_number| total_cost + (150*(floor_number**2)) }
end
# Let's say we want to build floors 50 to 59
floor_numbers = 50..59
# Pass that range into our Ruby method
calculate_building_cost_for(floor_numbers)
Running the above operation would evaluate to 4467750
.