Created
June 20, 2016 19:38
-
-
Save viebel/62d62220da0507860102c8ca6ad6db86 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
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