-
Notifications
You must be signed in to change notification settings - Fork 167
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
base: master
Are you sure you want to change the base?
Homework 1 #762
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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]] | ||
|
||
(1..(deep - 1)).each do |i| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. либо (deep - 1).times do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Используй более читаемые переменные вместо i, j, m и прочего. Ниже тоже. |
||
ar = [] | ||
(0..i).each do |j| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. require в начало файла |
||
size = IO.console.winsize | ||
|
||
(0..(deep - 1)).each do |i| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. аналогично выше. |
||
str = '' | ||
print "#{i}:" | ||
(0..i).each do |j| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. все странные числа лучше вынести в константы. не понятно почему все умножается или делится на 2. |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pascal_triangle
?