Skip to content

Instantly share code, notes, and snippets.

@pdxwolfy
Created May 1, 2016 21:35
Show Gist options
  • Save pdxwolfy/39d4957d08185189fd3258c2d2d0f036 to your computer and use it in GitHub Desktop.
Save pdxwolfy/39d4957d08185189fd3258c2d2d0f036 to your computer and use it in GitHub Desktop.
class Triangle
attr_reader :rows
def initialize height
factorial = [1]
1.upto(height).each { |n| factorial << n * factorial.last }
@rows = 0.upto(height - 1).map do |row|
0.upto(row).map { |seq| factorial[row] / (factorial[seq] * factorial[row - seq]) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment