Last active
December 9, 2015 16:58
-
-
Save flakyfilibuster/4300479 to your computer and use it in GitHub Desktop.
Times table in one line!
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) | |
(1..rows).each {|i| ((1..rows).each { |j| print "#{i*j}\t"}) && (print "\n")} | |
end | |
# Example output with "times_table(5)": | |
# 1 2 3 4 5 | |
# 2 4 6 8 10 | |
# 3 6 9 12 15 | |
# 4 8 12 16 20 | |
# 5 10 15 20 25 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment