-
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
Add homework-1 #770
base: master
Are you sure you want to change the base?
Add homework-1 #770
Changes from 5 commits
297385f
1f9d9c5
c9e2ce1
f605f48
f92b0ee
b33691b
d1da415
d80ad3c
81a8eb7
be29b4d
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,44 @@ | ||
class Triangle | ||
def initialize(base_number, deep) | ||
@base_number = base_number | ||
@deep = deep | ||
end | ||
|
||
def fact(a) | ||
(1..a).reduce(:*) | ||
end | ||
|
||
def binomial(n, k) | ||
return @base_number if n - k <= 0 || k <= 0 | ||
fact(n) / (fact(k) * fact(n - k)) * @base_number | ||
end | ||
|
||
def curr_str(n) | ||
(0..n).map { |e| binomial(n, e) } | ||
end | ||
|
||
def show | ||
max_row = curr_str(@deep) | ||
max_el_size = max_row.max.to_s.size | ||
width = [`tput cols`.to_i, 100].max | ||
@deep.times do |i| | ||
string = curr_str(i).map do |el| | ||
el.to_s.center(max_el_size) | ||
end.join(' ').center(width) | ||
puts "#{i + 1}: #{string}" | ||
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 | ||
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 31, 2 is not aligned with @deep.times do |i| at 26, 4. |
||
end | ||
|
||
puts 'Введите начальное значение:' | ||
|
||
base_number = gets.chomp.to_i | ||
|
||
puts 'Введите глубину треугольника:' | ||
|
||
deep = gets.chomp.to_i | ||
|
||
triangle = Triangle.new(base_number, deep) | ||
|
||
triangle.show | ||
|
||
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. 1 trailing blank lines detected. |
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 empty lines between method definitions.