Conversation
| coef[i + 1] = 0 | ||
| (i + 1).downto(1) do |j| | ||
| coef[j] = coef[j] + coef[j - 1] | ||
| end |
| print "#{i}:"; puts coef.join(" ").center(cols) | ||
| coef[i + 1] = 0 | ||
| (i + 1).downto(1) do |j| | ||
| coef[j] = coef[j] + coef[j - 1] |
There was a problem hiding this comment.
Tab detected.
Use 2 (not 1) spaces for indentation.
| 0.upto(tree_depth - 1) do |i| | ||
| print "#{i}:"; puts coef.join(" ").center(cols) | ||
| coef[i + 1] = 0 | ||
| (i + 1).downto(1) do |j| |
There was a problem hiding this comment.
Tab detected.
Inconsistent indentation detected.
Trailing whitespace detected.
| coef = [base_number] | ||
| cols = %x(/usr/bin/tput cols).chomp.to_i - 3 | ||
| 0.upto(tree_depth - 1) do |i| | ||
| print "#{i}:"; puts coef.join(" ").center(cols) |
There was a problem hiding this comment.
Do not use semicolons to terminate expressions.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
| #tree create | ||
| coef = [base_number] | ||
| cols = %x(/usr/bin/tput cols).chomp.to_i - 3 | ||
| 0.upto(tree_depth - 1) do |i| |
| tree_depth = gets.chomp.to_i | ||
| print "Input base number: "; | ||
| base_number = gets.chomp.to_i | ||
| #checking values |
| #values input | ||
| print "Input tree depth: "; | ||
| tree_depth = gets.chomp.to_i | ||
| print "Input base number: "; |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Do not use semicolons to terminate expressions.
| @@ -0,0 +1,21 @@ | |||
| #Program draws pascal's triangle with the specified depth in the console | |||
| #values input | |||
| print "Input tree depth: "; | |||
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Do not use semicolons to terminate expressions.
| @@ -0,0 +1,21 @@ | |||
| #Program draws pascal's triangle with the specified depth in the console | |||
| #values input | |||
| @@ -0,0 +1,21 @@ | |||
| #Program draws pascal's triangle with the specified depth in the console | |||
| cols = `/usr/bin/tput cols`.chomp.to_i | ||
| spaces = ' ' * (tree_depth / 4 > 0 ? tree_depth / 4 : 1) | ||
| 0.upto(tree_depth - 1) do |i| | ||
| printf("%03d:", i) |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Xanderwot
left a comment
There was a problem hiding this comment.
В целом нормально, но нужно писать прям очень читаемый код ;)
| # tree create | ||
| coef = [base_number] | ||
| cols = `/usr/bin/tput cols`.chomp.to_i | ||
| spaces = ' ' * (tree_depth / 4 > 0 ? tree_depth / 4 : 1) |
There was a problem hiding this comment.
вынеси 4 в константу и назови её как-то более дружелюбно
| coef = [base_number] | ||
| cols = `/usr/bin/tput cols`.chomp.to_i | ||
| spaces = ' ' * (tree_depth / 4 > 0 ? tree_depth / 4 : 1) | ||
| 0.upto(tree_depth - 1) do |i| |
There was a problem hiding this comment.
(0...tree_depth).each do |level|
| puts coef.join(spaces).center(cols) | ||
| coef.push(0) | ||
| (i + 1).downto(1) do |j| | ||
| coef[j] += coef[j - 1] |
There was a problem hiding this comment.
имена переменных j, i, n и прочее читать прям очень не удобно
| coef[column] += coef[column - 1] | ||
| end | ||
| end | ||
|
|
Homework 1: The Magic Triangle Pascals triangle with fix(i)es
Фамилия Имя
Добшиков Анатолий
Email
anatoly.dobshikov@mail.ru
Номер домашнего задания
1
Ссылка на видео с демо работы
https://www.youtube.com/watch?v=K4nAUYTvlzQ
Комментарии
Мой первый треугольник Паскаля...