Skip to content

Instantly share code, notes, and snippets.

@netsprout
Created March 28, 2015 05:05
Show Gist options
  • Save netsprout/b2b282faae3dc299ccbd to your computer and use it in GitHub Desktop.
Save netsprout/b2b282faae3dc299ccbd to your computer and use it in GitHub Desktop.
Generate HTML Multiplication Table
# AngelList Interview
# March 27, 2015
# create HTML table given width and height
#
# Example:
# w = 2
# h = 3
# would generate:
# - 1 2
# 1 1 2
# 2 2 4
# 3 3 6
def generate_table(width,height)
table = "<table>"
table += make_header(width)
(1..height).each do |y|
table += " \n<tr>\n"
table += " <td>#{y}</td>"
(1..width).each do |x|
table += " <td>#{x*y}</td>"
end
table += " \n</tr>\n"
end
table += "</table>\n"
end
def make_header(width)
puts "W: #{width}"
header = "\n<tr>\n"
(0..width).each do |w|
header += "<th>#{w}</th>"
end
header += "\n</tr>\n"
end
# Run program
puts generate_table(2,3)
@netsprout
Copy link
Author

Generate Multiplication Table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment