From c17ef16a350ef2d46a3bb7edb7718dc07d06ba29 Mon Sep 17 00:00:00 2001 From: 552687773 Date: Mon, 19 Feb 2018 23:38:17 +0300 Subject: [PATCH 1/6] hw 1 --- 2018/DmitryShkuratov/1/homework-1.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2018/DmitryShkuratov/1/homework-1.rb diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb new file mode 100644 index 000000000..f4d0d1f50 --- /dev/null +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -0,0 +1,27 @@ +class PascalsTriangle + def initialize + print "Enter the depth of the triangle:\n n=" + @rows = gets.chomp.to_i + end + + def to_pascal + temp = [] + @rows.times do |row| + line = [1] + (0..row-1).each {|x| line << (line[x] * (row-x) / (x+1)) } + temp << line + end + temp +end + + def print_triangle + max = to_pascal.flatten.max.to_s.length + strings = to_pascal.map {|arr| arr.map {|int| int.to_s.center(max + 3)} } + strings.each do |line| + puts line.join.center(strings[-1].join.length) + end + end +end + +row = PascalsTriangle.new +row.print_triangle From e6624e8f36edd2c2b98de5ec9bee5bd688215e0b Mon Sep 17 00:00:00 2001 From: 552687773 Date: Tue, 20 Feb 2018 00:18:05 +0300 Subject: [PATCH 2/6] fix styling --- 2018/DmitryShkuratov/1/homework-1.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb index f4d0d1f50..e9a9844dc 100644 --- a/2018/DmitryShkuratov/1/homework-1.rb +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -10,17 +10,17 @@ def to_pascal line = [1] (0..row-1).each {|x| line << (line[x] * (row-x) / (x+1)) } temp << line + end end temp -end + end def print_triangle max = to_pascal.flatten.max.to_s.length - strings = to_pascal.map {|arr| arr.map {|int| int.to_s.center(max + 3)} } + strings = to_pascal.map { |arr| arr.map { |int| int.to_s.center(max + 3)} } strings.each do |line| puts line.join.center(strings[-1].join.length) end - end end row = PascalsTriangle.new From 93392c215cb1b88049f1c2d8df659b32a2ff7b3d Mon Sep 17 00:00:00 2001 From: 552687773 Date: Tue, 20 Feb 2018 00:24:19 +0300 Subject: [PATCH 3/6] fix2 styling --- 2018/DmitryShkuratov/1/homework-1.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb index e9a9844dc..24d19d511 100644 --- a/2018/DmitryShkuratov/1/homework-1.rb +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -8,9 +8,9 @@ def to_pascal temp = [] @rows.times do |row| line = [1] - (0..row-1).each {|x| line << (line[x] * (row-x) / (x+1)) } + (0..row-1).each { |x| line << (line[x] * (row - x) / (x + 1)) } temp << line - end + end end temp end From a8668ef220ebff655c1b485c8b12437a4f2146fb Mon Sep 17 00:00:00 2001 From: 552687773 Date: Tue, 20 Feb 2018 00:26:26 +0300 Subject: [PATCH 4/6] fix3 styling --- 2018/DmitryShkuratov/1/homework-1.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb index 24d19d511..0ef46c701 100644 --- a/2018/DmitryShkuratov/1/homework-1.rb +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -13,14 +13,14 @@ def to_pascal end end temp - end +end def print_triangle max = to_pascal.flatten.max.to_s.length strings = to_pascal.map { |arr| arr.map { |int| int.to_s.center(max + 3)} } strings.each do |line| puts line.join.center(strings[-1].join.length) - end + end end row = PascalsTriangle.new From 24d28db0f3ec4ce79a09a0ed9289ce80fc8797e2 Mon Sep 17 00:00:00 2001 From: 552687773 Date: Tue, 20 Feb 2018 00:29:11 +0300 Subject: [PATCH 5/6] fix4 styling --- 2018/DmitryShkuratov/1/homework-1.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb index 0ef46c701..592fbace5 100644 --- a/2018/DmitryShkuratov/1/homework-1.rb +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -10,9 +10,9 @@ def to_pascal line = [1] (0..row-1).each { |x| line << (line[x] * (row - x) / (x + 1)) } temp << line + end end - end - temp +temp end def print_triangle From 9c90f1f91e412ae766c20f0750c5006ba92a0a61 Mon Sep 17 00:00:00 2001 From: 552687773 Date: Tue, 20 Feb 2018 00:36:56 +0300 Subject: [PATCH 6/6] last fix styling issues --- 2018/DmitryShkuratov/1/homework-1.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/2018/DmitryShkuratov/1/homework-1.rb b/2018/DmitryShkuratov/1/homework-1.rb index 592fbace5..33f135f8e 100644 --- a/2018/DmitryShkuratov/1/homework-1.rb +++ b/2018/DmitryShkuratov/1/homework-1.rb @@ -7,9 +7,9 @@ def initialize def to_pascal temp = [] @rows.times do |row| - line = [1] - (0..row-1).each { |x| line << (line[x] * (row - x) / (x + 1)) } - temp << line + line = [1] + (0..row-1).each { |x| line << (line[x] * (row - x) / (x + 1)) } + temp << line end end temp