Skip to content

Add homework-1 #770

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
45 changes: 45 additions & 0 deletions 2018/alexeymoissenko/hm-1/Pascal-tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class Triangle

Choose a reason for hiding this comment

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

Extra empty line detected at class body beginning.

def initialize (base_number, deep)

Choose a reason for hiding this comment

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

Do not put a space between a method name and the opening parenthesis.
Trailing whitespace detected.

@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

Choose a reason for hiding this comment

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

Surrounding space missing for operator -.

fact(n) / (fact(k) * fact(n - k)) * @base_number
end

def curr_str (n)

Choose a reason for hiding this comment

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

Do not put a space between a method name and the opening parenthesis.

Choose a reason for hiding this comment

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

Do not put a space between a method name and the opening parenthesis.

(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)

Choose a reason for hiding this comment

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

end at 29, 6 is not aligned with string = curr_str(i).map do |el| at 27, 8.
Prefer single-quoted strings when you don't need string interpolation or special symbols.

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.

puts "#{i+1}: #{string}"

Choose a reason for hiding this comment

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

Surrounding space missing for operator +.

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

Choose a reason for hiding this comment

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

1 trailing blank lines detected.
Trailing whitespace detected.