Skip to content

Instantly share code, notes, and snippets.

@viebel
Created June 20, 2016 19:38
Show Gist options
  • Save viebel/62d62220da0507860102c8ca6ad6db86 to your computer and use it in GitHub Desktop.
Save viebel/62d62220da0507860102c8ca6ad6db86 to your computer and use it in GitHub Desktop.
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