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

implement hw 1 #761

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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
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)

Choose a reason for hiding this comment

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

Space missing after comma.

fact(n) / ( fact(k) * fact(n-k) )

Choose a reason for hiding this comment

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

Space inside parentheses detected.
Surrounding space missing for operator -.

end

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

puts "Введите глубину дерева:"

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

three_len = gets.chomp.to_i
puts "Введите базовый номер:"

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.

first_el = gets.chomp.to_i

number_max_len = pascals_row(three_len, first_el).max.to_s.length #для вывода числа с нулями в начале, если его длинна меньше длинны максимального элемента

Choose a reason for hiding this comment

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

Missing space after #.
Use only ascii symbols in comments.
Line is too long. [155/80]

console_len = 160 # для центрирования дерева, значение для монитора 15" и разрешения 1366 х 768

Choose a reason for hiding this comment

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

Unnecessary spacing detected.
Use only ascii symbols in comments.
Line is too long. [96/80]

gaps = (" " * (number_max_len)) #для формирования отображения в консоле

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Don't use parentheses around a variable.
Missing space after #.
Use only ascii symbols in comments.

help_str = "\/#{gaps}\\#{gaps}" #задание шаблона отображения ветвей дерева

Choose a reason for hiding this comment

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

Missing space after #.
Use only ascii symbols in comments.

(0..three_len).each do |i|

Choose a reason for hiding this comment

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

Trailing whitespace detected.

str = "" #для создания строки вывода на консоль каждой строчки дерева

Choose a reason for hiding this comment

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

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Missing space after #.
Use only ascii symbols in comments.

pascals_row(i, first_el).each do
|elem| str += elem.to_s.rjust(number_max_len, '0') + (gaps + " ")

Choose a reason for hiding this comment

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

Block argument expression is not on the same line as the block start.
Prefer single-quoted strings when you don't need string interpolation or special symbols.

end
puts "#{" " * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) #ветви

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.
Prefer single-quoted strings inside interpolations.
Line is too long. [95/80]
Missing space after #.
Use only ascii symbols in comments.

puts "#{i.to_s.rjust(three_len.to_s.length, '0')}" + str.chomp(gaps + " ").center(console_len, ",") #элементы

Choose a reason for hiding this comment

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

Prefer to_s over string interpolation.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Line is too long. [112/80]
Missing space after #.
Use only ascii symbols in comments.

end

Choose a reason for hiding this comment

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

Trailing whitespace detected.