-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hw 1 #766
base: master
Are you sure you want to change the base?
hw 1 #766
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class PascalsTriangle | ||
def initialize | ||
print "Enter the depth of the triangle:\n n=" | ||
@rows = gets.chomp.to_i | ||
end | ||
|
||
def to_pascal | ||
temp = [] | ||
@rows.times do |row| | ||
line = [1] | ||
(0..row-1).each {|x| line << (line[x] * (row-x) / (x+1)) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surrounding space missing for operator -. |
||
temp << line | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end at 13, 2 is not aligned with @rows.times do |row| at 9, 4. |
||
temp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end at 15, 0 is not aligned with def at 7, 2. |
||
|
||
def print_triangle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent indentation detected. |
||
max = to_pascal.flatten.max.to_s.length | ||
strings = to_pascal.map {|arr| arr.map {|int| int.to_s.center(max + 3)} } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space between { and | missing. |
||
strings.each do |line| | ||
puts line.join.center(strings[-1].join.length) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 (not 0) spaces for indentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use 2 (not 0) spaces for indentation. |
||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end at 23, 3 is not aligned with def at 17, 2. |
||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end at 24, 0 is not aligned with def at 18, 2. |
||
|
||
row = PascalsTriangle.new | ||
row.print_triangle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 2 (not 0) spaces for indentation.