Created
March 18, 2013 20:40
-
-
Save ydawant/5190612 to your computer and use it in GitHub Desktop.
Times Table
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
def times_table(rows) | |
array = Array.new(rows) { Array.new(rows) } | |
y=0 | |
array.each do |x| | |
x.each do |i| | |
until y == rows | |
x[y] = 1 | |
x[y] *= (y + 1) | |
y += 1 | |
end | |
y=0 | |
end | |
puts "#{x}\n" | |
end | |
end |
So, this isn't a solution but it should help you get to one. Instead of storing an entire row in "x" and then printing that at the end, you can "print" each value plus a space (which will keep everything on one line), and then after that row is complete you can print a new line (i.e. print "/n"). It would require a bit of reworking to get rid of x, but I think it will make things more simple.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What we worked on: