Skip to content

Instantly share code, notes, and snippets.

@AKovtunov
Created June 10, 2018 12:37
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 AKovtunov/59828b1f45359a7afae275ace00458f5 to your computer and use it in GitHub Desktop.
Save AKovtunov/59828b1f45359a7afae275ace00458f5 to your computer and use it in GitHub Desktop.
codewars tower builder ruby
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
@yaroslavrick
Copy link

good job!

@AKovtunov
Copy link
Author

@yaroslavrick thank you! :)

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