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

implement hw1 #765

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
24 changes: 24 additions & 0 deletions 2018/SlepenkovDmitry/HomeWork1/HomeWork1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class PrintPascalTriangle
def initialize
print "Enter the depth of the triangle n = "
@rows = gets.chomp.to_i
end
def calculatedRow
triangle = []
@rows.times do |row|
line = [1]
(0..row-1).each {|x| line << (line[x] * (row-x) / (x+1)) }
triangle << line
end
triangle
end
def printTriangle
max = calculatedRow.flatten.max.to_s.length
strings = calculatedRow.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

row = PrintPascalTriangle.new
row.printTriangle