Skip to content

Instantly share code, notes, and snippets.

@viebel
Created June 20, 2016 19:38
def multiplication_table(n)
str = " |" + (" %3d" * n) % [*1..n]
str += "\n"
str += "----+" + "----" * n
str += "\n"
1.upto(n) do |x|
str += "%3d |" % x
1.upto(x-1) {|y| str += " "}
x.upto(n) {|y| str += " %3d" % (x*y)}
str += "\n"
end
str
end
multiplication_table 12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment