Created
June 10, 2018 12:37
-
-
Save AKovtunov/59828b1f45359a7afae275ace00458f5 to your computer and use it in GitHub Desktop.
codewars tower builder ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def towerBuilder(n_floors) | |
tower = [] | |
total_cells_taken = 2 * n_floors - 1 | |
n_floors.times do |floor| | |
floor_cells_taken = floor * 2 +1 | |
spaces_from_each_side = (total_cells_taken - floor_cells_taken) / 2 | |
spaces = ' ' * spaces_from_each_side | |
tower << "#{spaces}#{'*'*floor_cells_taken}#{spaces}" | |
end | |
return tower | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yaroslavrick thank you! :)