Skip to content

Instantly share code, notes, and snippets.

@flakyfilibuster
Last active December 9, 2015 16:58
Show Gist options
  • Save flakyfilibuster/4300479 to your computer and use it in GitHub Desktop.
Save flakyfilibuster/4300479 to your computer and use it in GitHub Desktop.
Times table in one line!
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