Created
May 1, 2016 21:35
-
-
Save pdxwolfy/39d4957d08185189fd3258c2d2d0f036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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