implement hw 1#761
implement hw 1#761ivkarpechenko wants to merge 12 commits intorubyroidlabs:masterfrom ivkarpechenko:homework-1
Conversation
2018/IvanKarpechanka/1/hw.rb
Outdated
| puts "#{" " * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) #ветви | ||
| puts "#{i.to_s.rjust(three_len.to_s.length, '0')}" + str.chomp(gaps + " ").center(console_len, ",") #элементы | ||
| end | ||
|
No newline at end of file |
2018/IvanKarpechanka/1/hw.rb
Outdated
| |elem| str += elem.to_s.rjust(number_max_len, '0') + (gaps + " ") | ||
| end | ||
| puts "#{" " * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) #ветви | ||
| puts "#{i.to_s.rjust(three_len.to_s.length, '0')}" + str.chomp(gaps + " ").center(console_len, ",") #элементы |
There was a problem hiding this comment.
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.
2018/IvanKarpechanka/1/hw.rb
Outdated
| pascals_row(i, first_el).each do | ||
| |elem| str += elem.to_s.rjust(number_max_len, '0') + (gaps + " ") | ||
| end | ||
| puts "#{" " * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) #ветви |
There was a problem hiding this comment.
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.
2018/IvanKarpechanka/1/hw.rb
Outdated
| (0..three_len).each do |i| | ||
| str = "" #для создания строки вывода на консоль каждой строчки дерева | ||
| pascals_row(i, first_el).each do | ||
| |elem| str += elem.to_s.rjust(number_max_len, '0') + (gaps + " ") |
There was a problem hiding this comment.
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.
2018/IvanKarpechanka/1/hw.rb
Outdated
| gaps = (" " * (number_max_len)) #для формирования отображения в консоле | ||
| help_str = "\/#{gaps}\\#{gaps}" #задание шаблона отображения ветвей дерева | ||
| (0..three_len).each do |i| | ||
| str = "" #для создания строки вывода на консоль каждой строчки дерева |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Missing space after #.
Use only ascii symbols in comments.
2018/IvanKarpechanka/1/hw.rb
Outdated
| puts "Введите базовый номер:" | ||
| first_el = gets.chomp.to_i | ||
|
|
||
| number_max_len = pascals_row(three_len, first_el).max.to_s.length #для вывода числа с нулями в начале, если его длинна меньше длинны максимального элемента |
There was a problem hiding this comment.
Missing space after #.
Use only ascii symbols in comments.
Line is too long. [155/80]
2018/IvanKarpechanka/1/hw.rb
Outdated
|
|
||
| puts "Введите глубину дерева:" | ||
| three_len = gets.chomp.to_i | ||
| puts "Введите базовый номер:" |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
2018/IvanKarpechanka/1/hw.rb
Outdated
| (0..row).map { |line| first_el * binom(row, line) } | ||
| end | ||
|
|
||
| puts "Введите глубину дерева:" |
There was a problem hiding this comment.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
2018/IvanKarpechanka/1/hw.rb
Outdated
| end | ||
|
|
||
| def binom(n,k) | ||
| fact(n) / ( fact(k) * fact(n-k) ) |
There was a problem hiding this comment.
Space inside parentheses detected.
Surrounding space missing for operator -.
2018/IvanKarpechanka/1/hw.rb
Outdated
| (1..n).inject(1, :*) | ||
| end | ||
|
|
||
| def binom(n,k) |
2018/IvanKarpechanka/1/hw.rb
Outdated
| end | ||
| puts "#{' ' * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) | ||
| puts "#{i.to_s.rjust(three_len.to_s.length, '0')}" + str.chomp(gaps + ' ').center(console_len, ',') | ||
| end No newline at end of file |
2018/IvanKarpechanka/1/hw.rb
Outdated
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| puts "#{' ' * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) | ||
| puts "#{i.to_s.rjust(three_len.to_s.length, '0')}" + str.chomp(gaps + ' ').center(console_len, ',') |
There was a problem hiding this comment.
Prefer to_s over string interpolation.
Line is too long. [102/80]
2018/IvanKarpechanka/1/hw.rb
Outdated
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| puts "#{' ' * three_len.to_s.length}" + (help_str * i).chomp(gaps).center(console_len) |
There was a problem hiding this comment.
Prefer to_s over string interpolation.
Line is too long. [88/80]
2018/IvanKarpechanka/1/hw.rb
Outdated
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree | ||
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') |
There was a problem hiding this comment.
Use 2 (not 1) spaces for indentation.
2018/IvanKarpechanka/1/hw.rb
Outdated
| # to output a number with zeros in the beginning if its length is less than the length of the maximum element | ||
| number_max_len = pascals_row(three_len, first_el).max.to_s.length | ||
| console_len = 160 | ||
| gaps = (' ' * (number_max_len)) |
There was a problem hiding this comment.
Don't use parentheses around a variable.
2018/IvanKarpechanka/1/hw.rb
Outdated
| puts 'Введите базовый номер:' | ||
| first_el = gets.chomp.to_i | ||
|
|
||
| # to output a number with zeros in the beginning if its length is less than the length of the maximum element |
2018/IvanKarpechanka/1/hw.rb
Outdated
| help1 = "#{' ' * three_len.to_s.length}" | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) | ||
|
|
||
| help2 = "#{i.to_s.rjust(three_len.to_s.length, '0')}" |
There was a problem hiding this comment.
Prefer to_s over string interpolation.
2018/IvanKarpechanka/1/hw.rb
Outdated
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree | ||
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') |
There was a problem hiding this comment.
Use 2 (not 1) spaces for indentation.
Tab detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| puts 'Введите базовый номер:' | ||
| first_el = gets.chomp.to_i | ||
|
|
||
| # to output a number with zeros in the beginning if its |
| help1 = ' ' * three_len.to_s.length | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) | ||
| help2 = i.to_s.rjust(three_len.to_s.length, '0') | ||
| puts help2 + str.chomp(gaps + ' ').center(console_len, ',') |
There was a problem hiding this comment.
Inconsistent indentation detected.
| end | ||
| help1 = ' ' * three_len.to_s.length | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) | ||
| help2 = i.to_s.rjust(three_len.to_s.length, '0') |
There was a problem hiding this comment.
Inconsistent indentation detected.
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| help1 = ' ' * three_len.to_s.length | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) |
There was a problem hiding this comment.
Inconsistent indentation detected.
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| help1 = ' ' * three_len.to_s.length |
There was a problem hiding this comment.
Inconsistent indentation detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree | ||
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') |
There was a problem hiding this comment.
Use 2 (not 1) spaces for indentation.
Tab detected.
| help_str = "\/#{gaps}\\#{gaps}" # Specifying a Tree Display Template | ||
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree | ||
| pascals_row(i, first_el).each do |elem| |
There was a problem hiding this comment.
Inconsistent indentation detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| gaps = (' ' * number_max_len) | ||
| help_str = "\/#{gaps}\\#{gaps}" # Specifying a Tree Display Template | ||
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree |
There was a problem hiding this comment.
Use 2 (not 1) spaces for indentation.
Tab detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| gaps = (' ' * number_max_len) | ||
| help_str = "\/#{gaps}\\#{gaps}" # Specifying a Tree Display Template | ||
| (0..three_len).each do |i| | ||
| str = '' # to create an output line on the console of each line of the tree |
There was a problem hiding this comment.
Use 2 (not 0) spaces for indentation.
2018/IvanKarpechanka/1/hw.rb
Outdated
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| help1 = ' ' * three_len.to_s.length | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) |
There was a problem hiding this comment.
Inconsistent indentation detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| help1 = ' ' * three_len.to_s.length |
There was a problem hiding this comment.
Inconsistent indentation detected.
2018/IvanKarpechanka/1/hw.rb
Outdated
| help_str = "\/#{gaps}\\#{gaps}" | ||
| (0..three_len).each do |i| | ||
| str = '' | ||
| pascals_row(i, first_el).each do |elem| |
There was a problem hiding this comment.
Inconsistent indentation detected.
| gaps = (' ' * number_max_len) | ||
| help_str = "\/#{gaps}\\#{gaps}" | ||
| (0..three_len).each do |i| | ||
| str = '' |
| console_len = `tput cols`.to_i | ||
| gaps = (' ' * number_max_len) | ||
| help_str = "\/#{gaps}\\#{gaps}" | ||
| (0..three_len).each do |i| |
There was a problem hiding this comment.
three_len.times do |tree_level|
| @@ -0,0 +1,30 @@ | |||
| def fact(n) | |||
There was a problem hiding this comment.
Используй более дружелюбные переменные, чтобы можно было читать код легко, а не гадать что такое n, k или j
| pascals_row(i, first_el).each do |elem| | ||
| str += elem.to_s.rjust(number_max_len, '0') + (gaps + ' ') | ||
| end | ||
| help1 = ' ' * three_len.to_s.length |
There was a problem hiding this comment.
help1 прям очень плохо. Я уверен ты можешь лучше.
| end | ||
| help1 = ' ' * three_len.to_s.length | ||
| puts help1 + (help_str * i).chomp(gaps).center(console_len) | ||
| help2 = i.to_s.rjust(three_len.to_s.length, '0') |
Фамилия Имя
Карпеченко Иван
Email
ivkarpechenko@gmail.com
Номер домашнего задания
1
Ссылка на видео с демо работы
https://www.youtube.com/watch?v=Kcgrlq_8YaY
Комментарии
Нету