Last active
August 29, 2015 14:01
-
-
Save lucascaton/567cedfc9f03ed09e9d8 to your computer and use it in GitHub Desktop.
This file contains 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
if ARGV.count > 2 | |
puts 'ERROR - Wrong arguments' | |
puts 'Usage: `ruby grid.rb <size> <grid_padding>`' | |
exit | |
end | |
size = (ARGV[0] || 10).to_i | |
grid_padding = (ARGV[1] || 2).to_i | |
grid = Array.new(size) { Array.new(size) { ['o', ' '].sample } } | |
border_partial = "+-#{'--' * grid_padding}" | |
border = "#{border_partial * size}+" | |
puts border | |
grid.each do |row| | |
row.each_with_index do |element, i| | |
print '|' if i == 0 | |
print "#{' ' * grid_padding}#{element}#{' ' * grid_padding}" | |
print (i == size - 1 ? '|' : ' ') | |
end | |
puts | |
(grid_padding - 1).times do | |
print "|#{' ' * ((((grid_padding * 2) + 2) * size) - 1)}|\n" | |
end | |
end | |
puts border |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment