Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions 2018/alexeymoissenko/hm-1/Pascal-tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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

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.

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}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent indentation detected.

end
end

Choose a reason for hiding this comment

The 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