Skip to content

Instantly share code, notes, and snippets.

@Yorgg
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yorgg/049e0c6bffa02b77f400 to your computer and use it in GitHub Desktop.
Save Yorgg/049e0c6bffa02b77f400 to your computer and use it in GitHub Desktop.
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