Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiplication table in ruby
#Multiplication table in Ruby with nested arrays
#[[1, 2, 3, 4],
# [2, 4, 6, 8],
# [3, 6, 9, 12],
# [4, 8, 12, 16]]
def multiplication_table(size)
Array.new(size) {|n| n+=1}.map do |row|
Array.new(size) {|col| col+=1; row*col}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment