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

Homework 1 #762

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
29 changes: 29 additions & 0 deletions 2018/VladislavShkrabkov/hw-1/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
puts 'Enter deep'
deep = gets.chomp.to_i
puts 'Enter basic value'
basic_val = gets.chomp.to_i
pasc_tri = [[basic_val]]
Copy link
Contributor

Choose a reason for hiding this comment

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

pascal_triangle?


(1..(deep - 1)).each do |i|
Copy link
Contributor

Choose a reason for hiding this comment

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

либо (deep - 1).times do
либо (1...deep).each do

Copy link
Contributor

Choose a reason for hiding this comment

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

Используй более читаемые переменные вместо i, j, m и прочего. Ниже тоже.

ar = []
(0..i).each do |j|
Copy link
Contributor

Choose a reason for hiding this comment

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

times

if i == j || j.zero?
ar.push(basic_val)
else
ar.push(pasc_tri[i - 1][j] + pasc_tri[i - 1][j - 1])
end
end
pasc_tri.push(ar)
end

require 'io/console'
Copy link
Contributor

Choose a reason for hiding this comment

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

require в начало файла

size = IO.console.winsize

(0..(deep - 1)).each do |i|
Copy link
Contributor

Choose a reason for hiding this comment

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

аналогично выше.

str = ''
print "#{i}:"
(0..i).each do |j|
Copy link
Contributor

Choose a reason for hiding this comment

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

times

str += (pasc_tri[i][j].to_s + (' ' * (size[1] / (deep * 2))))
end
puts ' ' * (size[1] / 2 - ((str.length - size[1] / (deep * 2)) / 2) - 2) + str
Copy link
Contributor

Choose a reason for hiding this comment

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

все странные числа лучше вынести в константы. не понятно почему все умножается или делится на 2.

end