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 hw 1 #773

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 6 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
31 changes: 31 additions & 0 deletions 2018/KuikoIhar/1/pas_tri.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby

Choose a reason for hiding this comment

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

Script file pas_tri.rb doesn't have execute permission.


def pas_tri(h, n)
l = [n]
[l] + (1..h).map do
l = [n] + l[1..-1].map.with_index { |x, i| x + l[i] } + [n]
end
end

def pad(s, n)
l = n - s.size
' ' * (l / 2) + s + ' ' * (l - l / 2)
end

def lines(rows)
n = rows[-1].max.to_s.size
rows.map do

Choose a reason for hiding this comment

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

Trailing whitespace detected.

|row| row.map { |x| pad(x.to_s, n) }.join(' ')

Choose a reason for hiding this comment

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

Block argument expression is not on the same line as the block start.

end
end

def center(l)
n = l[-1].size
l.map { |s| pad(s, n) }
end

puts 'Введите глубину дерева: '
h = gets.chomp.to_i
puts 'Введите базовый номер: '
n = gets.chomp.to_i
puts center lines pas_tri(h, n)