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

homework 1 #763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
44 changes: 44 additions & 0 deletions 2018/YuliyaBondareva/1/pascal_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'terminfo'

def tree(number, base_number)
width = TermInfo.screen_size
puts 'Pascal triangle'.center(width[1].to_i)
number.times do |index|
trn = [base_number]
temp = base_number
s = 1
branch = [' /']
index.times do
temp = ((temp * (index - s + 1)) / s)
trn.push temp
s += 1
branch.push ' /'
end
arr_to_str = trn.join(' ')
str_end = branch.join(' \\')
puts "#{index + 1}:" + ' ' + arr_to_str.center(width[1].to_i)
if index != (number - 1)
puts ' ' + "#{str_end} \\".center(width[1].to_i)
end
end
end

puts 'Depth?'
number = gets.chomp
base_number = ENV['BASE']
if number.to_i <= 0
loop do
puts 'depth must be positive. '
puts 'Depth?'
number = gets.chomp
break if number.to_i > 0
end
elsif base_number.to_i <= 0
loop do
puts 'BASE must be positive. '
puts 'BASE?'
base_number = gets.chomp
break if base_number.to_i > 0
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token kEND

tree(number.to_i, base_number.to_i)