Skip to content

Instantly share code, notes, and snippets.

@pjkelly
Created March 8, 2012 00:38
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 pjkelly/1997599 to your computer and use it in GitHub Desktop.
Save pjkelly/1997599 to your computer and use it in GitHub Desktop.
Calculating Time and Cost of Building Floors in Tiny Tower

Calculating Construction Cost

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.

Calculating Construction Time

According to the Tiny Tower Wiki the equation for calculating how long it takes to build a given floor is:

time_in_minutes = 30 × (floor_number - 1)

A simple way to evaluate this equation in Ruby would be:

floor_number = 10
time_in_minutes = 30*(floor_number-1)

# Wrapped in a method
def calculate_construction_time_for(floor_number)
  30*(floor_number-1)
end

# Let's say we want to build floor 52
floor_number = 52
# Pass that floor number into our Ruby method
calculate_construction_time_for(floor_number)

Running the above operation would evaluate to 1530 minutes, or approximately 25 hours.

It does not make sense to calculate the construction time for a group of floors because the construction time is always based on the top floor of the tower.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment