Skip to content
30 changes: 30 additions & 0 deletions 2018/IvanKarpechanka/1/hw.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def fact(n)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Используй более дружелюбные переменные, чтобы можно было читать код легко, а не гадать что такое n, k или j

(1..n).inject(1, :*)
end

def binom(n, k)
fact(n) / (fact(k) * fact(n - k))
end

def pascals_row(row, first_el)
(0..row).map { |line| first_el * binom(row, line) }
end

puts 'Введите глубину дерева:'
three_len = gets.chomp.to_i
puts 'Введите базовый номер:'
first_el = gets.chomp.to_i
number_max_len = pascals_row(three_len, first_el).max.to_s.length
console_len = `tput cols`.to_i
gaps = (' ' * number_max_len)
help_str = "\/#{gaps}\\#{gaps}"
(0..three_len).each do |i|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

three_len.times do |tree_level|

str = ''

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 пробела

pascals_row(i, first_el).each do |elem|
str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ')
end
help1 = ' ' * three_len.to_s.length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

help1 прям очень плохо. Я уверен ты можешь лучше.

puts help1 + (help_str * i).chomp(gaps).center(console_len)
help2 = i.to_s.rjust(three_len.to_s.length, '0')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

аналогично с help1

puts help2 + str.chomp(gaps + ' ').center(console_len, ',')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inconsistent indentation detected.

end